1import{j as e}from"./vendor-markdown-3uENCkuS.js";import{d as le,u as re,r as o}from"./vendor-react-router-fbnoKto0.js";import{F as ie,W as ne,X as L,u as R,Z as F,Y as D,_ as $,$ as T,a0 as O,g as U}from"./vendor-icons-kV6MQrcF.js";import{j as oe,u as C}from"./vendor-redux-8frB-79w.js";import{aI as A,aA as de,aw as ce,aJ as xe,l as B,aK as me}from"./index-zslOFxNg.js";import{T as pe}from"./TableSkeleton-BJuV56D2.js";import{M as W,l as _,p as q}from"./vendor-antd-CYdTsTmT.js";import"./vendor-react-dom-CekZHfxh.js";import"./vendor-reactflow-CEYCdEGm.js";import"./vendor-recharts-DJYAw1LN.js";import"./vendor-syntax-highlighter-1lJlPebH.js";const ge=l=>Array.isArray(l)?l:l?[l]:[],he=l=>Array.isArray(l.roles)&&l.roles.length>0?l.roles:Array.isArray(l.usertype)&&l.usertype.length>0?l.usertype:typeof l.usertype=="string"&&l.usertype?[l.usertype]:["Sales"],_e=()=>{const l=oe(),Q=le(),z=re(),Y=z.pathname.startsWith("/super-manager")?"/super-manager":z.pathname.startsWith("/cx-executive")?"/cx-executive":"/admin",{data:c,loading:P,saving:Z,deleting:ue,error:h}=C(s=>s.admin.salesManagement)||{data:[],loading:!1,saving:!1,deleting:!1,error:null},{data:x}=C(s=>s.common.roles),{data:g}=C(s=>s.common.locations),H=Array.isArray(g)?g:[],[J,y]=o.useState(!1),[K,V]=o.useState([]),[I,u]=o.useState("+91"),[f,N]=o.useState(""),[t,d]=o.useState({id:"",_id:"",empId:"",name:"",email:"",roles:["Sales"],location:[]}),[b,X]=o.useState(""),[v,G]=o.useState(1),w=10,ee=/^(?!.*\.\.)[a-zA-Z0-9._%+-]+@(codegnan\.(com|in|org)|destinationtechs\.(com|in)|gmail\.(com|in))$/,se=/^[9876]\d{9}$/,m={success:(s,a)=>q.success({message:s,description:a,duration:2.5}),error:(s,a)=>q.error({message:s,description:a,duration:3})};o.useEffect(()=>{const s=[{value:"+91",label:"+91"},{value:"+1",label:"+1"},{value:"+44",label:"+44"},{value:"+61",label:"+61"}].sort((a,r)=>a.label.localeCompare(r.label));V(s),u("+91")},[]),o.useEffect(()=>{l(A()),x!=null&&x.length||l(de()),g!=null&&g.length||l(ce())},[l]),o.useEffect(()=>{h&&m.error("Error",typeof h=="string"?h:"Failed to load data")},[h]);const k=(s=null)=>{var a;if(s){const r=((a=s.PhNumber)==null?void 0:a.match(/^(\+\d+)(\d{10})$/))||["","+91",""],n=r[1]||"+91",i=r[2]||"";d({id:s.id||"",_id:s._id||"",empId:s.empId||"",name:s.name||"",email:s.email||"",location:ge(s.location),roles:he(s)}),u(n),N(i)}else d({id:"",_id:"",empId:"",name:"",email:"",location:[],roles:["Sales"]}),u("+91"),N("");y(!0)},te=async()=>{if(!t.empId||!t.name||!t.email||!f||t.roles.length===0||t.location.length===0)return m.error("Validation Error","Please fill all required fields (including location).");if(!ee.test(t.email))return m.error("Invalid Email","Check email format.");if(!se.test(f))return m.error("Invalid Phone","10 digits starting with 6-9.");const{userType:s,id:a,_id:r,...n}=t,i={...n,PhNumber:(I||"+91")+f};a&&(i.id=a),r&&(i._id=r);try{await l(me(i)).unwrap();const p=t.id||t._id?"update":"post";B(p,`Sales representative ${t.id?"updated":"created"}: ${t.name}`),m.success("Success",`Sales representative ${t.id?"updated":"added"} successfully!`),y(!1),l(A())}catch(p){console.error("Save failed:",p)}},M=(s,a)=>{W.confirm({title:"Are you sure?",content:"This action cannot be undone!",okText:"Yes, delete it",cancelText:"Cancel",okButtonProps:{danger:!0},centered:!0,onOk:async()=>{try{await l(xe(s)).unwrap(),B("delete",`Sales representative deleted: ${a}`),m.success("Deleted","Removed successfully!"),l(A())}catch(r){console.error("Delete failed:",r)}}})},S=o.useMemo(()=>{let s=Array.isArray(c)?c:[];if(b.trim()){const a=b.toLowerCase().trim();s=s.filter(r=>{var n,i,p;return((n=r.name)==null?void 0:n.toLowerCase().includes(a))||((i=r.email)==null?void 0:i.toLowerCase().includes(a))||((p=r.empId)==null?void 0:p.toLowerCase().includes(a))})}return s},[c,b]),j=S.slice((v-1)*w,v*w),E=Math.ceil(S.length/w),ae={total:(c==null?void 0:c.length)||0};return e.jsxs("div",{className:"w-full px-4 sm:px-6 font-[inter] min-h-screen pb-10",children:[e.jsxs("div",{className:"relative flex flex-col sm:flex-row sm:justify-between sm:items-center mb-6 sm:mb-8 bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6 mt-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("button",{onClick:()=>Q(`${Y}/management-dashboard`),className:"group flex items-center gap-2 text-gray-400 hover:text-indigo-600 transition-colors font-medium text-[10px] sm:text-xs mb-2 sm:mb-3",children:[e.jsx(ie,{size:14,className:"group-hover:-translate-x-1 transition-transform sm:w-4 sm:h-4"}),"Back to Management"]}),e.jsx("h2",{className:"font-bold text-xl sm:text-2xl text-gray-900 leading-tight",children:"Sales Management"}),e.jsx("p",{className:"text-[11px] sm:text-sm text-gray-500 mt-1",children:"Manage sales representatives and executive access"})]}),e.jsxs("button",{onClick:()=>k(),className:"w-full sm:w-auto font-bold text-xs sm:text-sm text-white bg-gradient-to-r from-indigo-600 to-blue-600 hover:from-indigo-700 hover:to-blue-700 rounded-lg px-5 py-2.5 sm:py-3 inline-flex items-center justify-center gap-2 shadow-md hover:shadow-lg transition-all active:scale-[0.98]",children:[e.jsx(ne,{size:18})," Add Sales Rep"]})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-6 mb-6 sm:mb-8 text-[inter]",children:e.jsxs("div",{className:"bg-white p-3 sm:p-6 rounded-xl border border-gray-200 shadow-sm flex flex-col sm:flex-row items-start sm:items-center gap-3 sm:gap-5 transition-all hover:shadow-md",children:[e.jsx("div",{className:"w-10 h-10 sm:w-12 sm:h-12 rounded-lg bg-indigo-50 flex items-center justify-center text-indigo-600 shrink-0",children:e.jsx(L,{size:20,className:"sm:w-6 sm:h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-gray-500 uppercase tracking-wider",children:"Total Sales Reps"}),e.jsxs("h3",{className:"text-base sm:text-2xl font-bold text-gray-900 mt-0.5",children:[ae.total," ",e.jsx("span",{className:"text-[10px] sm:text-xs font-normal text-gray-400 ml-1",children:"Headcount"})]})]})]})}),e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-200 p-3 mb-4 text-[inter]",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:"flex-1 min-w-[200px] w-full sm:w-auto",children:e.jsx("input",{type:"text",name:"sales-find-search",autoComplete:"one-time-code",placeholder:"ð Search name, email, or ID...",className:"w-full px-3 sm:px-4 py-2 text-xs sm:text-sm border-2 border-gray-100 rounded-lg focus:outline-none focus:ring-4 focus:ring-indigo-50 focus:border-indigo-400 transition-all",value:b,onChange:s=>X(s.target.value)})}),e.jsxs("div",{className:"text-[10px] sm:text-xs font-bold text-gray-400 uppercase tracking-widest ml-auto px-2",children:[S.length," Results"]})]})}),e.jsxs("div",{className:"bg-white rounded-xl shadow-md border border-gray-200 overflow-hidden",children:[e.jsx("div",{className:"hidden sm:block overflow-x-auto no-scrollbar",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gradient-to-r from-indigo-600 to-blue-600 text-white",children:[e.jsx("th",{className:"px-6 py-4 text-left text-xs font-bold uppercase tracking-widest",children:"Emp ID"}),e.jsx("th",{className:"px-6 py-4 text-left text-xs font-bold uppercase tracking-widest",children:"Representative Details"}),e.jsx("th",{className:"px-6 py-4 text-left text-xs font-bold uppercase tracking-widest",children:"Locations"}),e.jsx("th",{className:"px-6 py-4 text-left text-xs font-bold uppercase tracking-widest",children:"Role"}),e.jsx("th",{className:"px-6 py-4 text-center text-xs font-bold uppercase tracking-widest",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:P?e.jsx(pe,{rows:6,cols:5}):j.length>0?j.map(s=>{var a,r;return e.jsxs("tr",{className:"hover:bg-indigo-50/30 transition-colors group",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:"px-2 py-1 rounded-md text-xs font-bold bg-indigo-50 text-indigo-700 border border-indigo-100",children:s.empId||"N/A"})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-700 text-sm font-bold shadow-sm shrink-0 uppercase border-2 border-white group-hover:scale-110 transition-transform",children:(r=(a=s.name)==null?void 0:a.trim())==null?void 0:r.charAt(0)}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-gray-900 leading-tight mb-0.5",children:s.name}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 font-medium",children:[e.jsx(R,{size:12,className:"text-indigo-400"}),s.email]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 font-medium tracking-tight",children:[e.jsx(F,{size:11,className:"text-emerald-400"}),s.PhNumber||"N/A"]})]})]})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("div",{className:"flex flex-wrap gap-1.5 max-w-[220px]",children:Array.isArray(s.location)&&s.location.length>0?s.location.map((n,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg text-[10px] font-bold bg-purple-50 text-purple-700 border border-purple-100 uppercase tracking-tighter",children:[e.jsx(D,{size:9})," ",n]},i)):e.jsx("span",{className:"text-[10px] text-gray-400 italic",children:"No locations"})})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("div",{className:"flex flex-wrap gap-1.5 text-inter",children:(Array.isArray(s.roles)?s.roles:[s.roles]).map((n,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-100 shadow-sm transition-all hover:bg-emerald-100",children:[e.jsx($,{size:10,
1className:"text-emerald-500"})," ",n]},i))})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex justify-center items-center gap-2",children:[e.jsx("button",{onClick:()=>k(s),className:"p-2 text-indigo-600 hover:bg-indigo-100 rounded-lg transition-all active:scale-90",children:e.jsx(T,{size:16})}),e.jsx("button",{onClick:()=>M(s.id||s._id,s.name),className:"p-2 text-red-500 hover:bg-red-50 rounded-lg transition-all active:scale-90",children:e.jsx(O,{size:16})})]})})]},s.id||s._id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:"5",className:"p-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 opacity-40",children:[e.jsx(L,{size:40,className:"text-gray-300"}),e.jsx("span",{className:"text-sm font-medium text-gray-500 italic",children:"No representatives found"})]})})})})]})}),e.jsx("div",{className:"sm:hidden divide-y divide-gray-100",children:P?e.jsx("div",{className:"p-8 text-center animate-pulse text-indigo-600",children:"Loading Sales Data..."}):j.length>0?j.map(s=>{var a,r;return e.jsxs("div",{className:"p-4 bg-white hover:bg-indigo-50/30 transition-colors",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-blue-600 flex items-center justify-center text-white text-sm font-bold shadow-md shrink-0 uppercase",children:(r=(a=s.name)==null?void 0:a.trim())==null?void 0:r.charAt(0)}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-gray-900 leading-tight",children:s.name}),e.jsx("p",{className:"text-[10px] font-bold text-indigo-600 uppercase tracking-widest mt-0.5",children:s.empId})]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>k(s),className:"p-2 text-indigo-600 bg-indigo-50 rounded-lg active:scale-90 transition-transform",children:e.jsx(T,{size:14})}),e.jsx("button",{onClick:()=>M(s.id||s._id,s.name),className:"p-2 text-red-500 bg-red-50 rounded-lg active:scale-90 transition-transform",children:e.jsx(O,{size:14})})]})]}),e.jsxs("div",{className:"space-y-2 mt-4 px-1",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-600",children:[e.jsx(R,{className:"text-indigo-400 shrink-0"}),e.jsx("span",{className:"truncate",children:s.email})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-600",children:[e.jsx(F,{className:"text-emerald-400 shrink-0"}),e.jsx("span",{children:s.PhNumber||"N/A"})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:Array.isArray(s.location)&&s.location.map((n,i)=>e.jsx("span",{className:"px-2 py-0.5 rounded bg-purple-50 text-purple-700 text-[10px] font-bold border border-purple-100 uppercase tracking-tighter",children:n},i))}),e.jsxs("div",{className:"mt-3 py-2 border-t border-gray-50 flex items-center gap-2",children:[e.jsx($,{size:12,className:"text-emerald-500"}),e.jsx("span",{className:"text-[10px] font-black text-emerald-700 uppercase tracking-widest",children:(Array.isArray(s.roles)?s.roles:[s.roles]).join(" ⢠")})]})]},s.id||s._id)}):e.jsx("div",{className:"p-12 text-center text-gray-400 italic text-sm",children:"No entries found"})})]}),E>1&&e.jsx("div",{className:"flex justify-center mt-6",children:e.jsx("div",{className:"flex items-center gap-1 bg-white px-2 py-1.5 sm:px-3 sm:py-2 rounded-xl shadow-sm border border-gray-200",children:Array.from({length:E},(s,a)=>a+1).map(s=>e.jsx("button",{onClick:()=>G(s),className:`w-8 h-8 sm:w-9 sm:h-9 rounded-lg font-bold text-xs sm:text-sm transition-all ${v===s?"bg-indigo-600 text-white shadow-md":"text-gray-600 hover:bg-gray-100"}`,children:s},s))})}),e.jsx(W,{title:e.jsxs("div",{className:"flex items-center gap-3 py-1 sm:py-2",children:[e.jsxs("div",{className:"w-9 h-9 sm:w-11 sm:h-11 bg-indigo-50 rounded-lg sm:rounded-xl flex items-center justify-center text-indigo-600 shrink-0",children:[e.jsx(U,{size:20,className:"sm:hidden"}),e.jsx(U,{size:24,className:"hidden sm:block"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{className:"text-base sm:text-xl font-bold text-gray-900 leading-none",children:t.id||t._id?"Update Sales Rep":"Add Sales Rep"}),e.jsx("div",{className:"text-[10px] sm:text-xs text-gray-400 font-medium mt
1-1 uppercase tracking-tight",children:"Sales Executive Professional Profile"})]})]}),open:J,onCancel:()=>y(!1),onOk:te,okText:t.id||t._id?"Update Details":"Save Details",confirmLoading:Z,width:700,centered:!0,className:"text-[inter]",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 sm:gap-5 py-2 sm:py-4",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"text-[11px] sm:text-sm font-bold text-gray-500 uppercase tracking-tighter",children:["Employee ID ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{name:"sales_emp_id_field",autoComplete:"none",placeholder:"e.g. SL123",className:"px-3 sm:px-4 py-2 sm:py-2.5 border-2 border-gray-100 rounded-xl text-xs sm:text-base outline-none focus:ring-4 focus:ring-indigo-50 focus:border-indigo-400 transition-all placeholder:text-gray-300",value:t.empId,onChange:s=>d({...t,empId:s.target.value})})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"text-[11px] sm:text-sm font-bold text-gray-500 uppercase tracking-tighter",children:["Full Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{name:"sales_full_name_field",autoComplete:"none",placeholder:"Enter full name",className:"px-3 sm:px-4 py-2 sm:py-2.5 border-2 border-gray-100 rounded-xl text-xs sm:text-base outline-none focus:ring-4 focus:ring-indigo-50 focus:border-indigo-400 transition-all placeholder:text-gray-300",value:t.name,onChange:s=>d({...t,name:s.target.value})})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"text-[11px] sm:text-sm font-bold text-gray-500 uppercase tracking-tighter",children:["Official Email ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",name:"sales_official_email_field",autoComplete:"new-password",placeholder:"e.g. [email protected]",className:"px-3 sm:px-4 py-2 sm:py-2.5 border-2 border-gray-100 rounded-xl text-xs sm:text-base outline-none focus:ring-4 focus:ring-indigo-50 focus:border-indigo-400 transition-all placeholder:text-gray-300",value:t.email,onChange:s=>d({...t,email:s.target.value})})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"text-[11px] sm:text-sm font-bold text-gray-500 uppercase tracking-tighter",children:["Phone Number ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"flex border-2 border-gray-100 rounded-xl overflow-hidden focus-within:ring-4 focus-within:ring-indigo-50 focus-within:border-indigo-400 transition-all",children:[e.jsx(_,{options:K,value:I,onChange:u,className:"mgmt-select-country w-[80px] sm:w-[100px] text-xs sm:text-base"}),e.jsx("input",{name:"sales_phone_number_field",autoComplete:"none",placeholder:"00000 00000",className:"flex-1 px-3 sm:px-4 py-2 sm:py-2.5 outline-none text-xs sm:text-base placeholder:text-gray-300 font-mono tracking-wider",value:f,onChange:s=>N(s.target.value)})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex justify-between items-center mb-0.5",children:[e.jsxs("label",{className:"text-[11px] sm:text-sm font-bold text-gray-500 uppercase tracking-tighter",children:["Authorized Locations ",e.jsx("span",{className:"text-red-500",children:"*"})]}),t.location.length>0&&e.jsx("button",{onClick:()=>d({...t,location:[]}),className:"text-[9px] sm:text-[10px] font-bold text-red-500 hover:text-red-700 uppercase tracking-tighter bg-red-50 px-2 py-0.5 rounded cursor-pointer",children:"Clear All"})]}),e.jsx(_,{options:H.filter(s=>!t.location.includes(s)).map(s=>({value:s,label:s})),value:void 0,onChange:s=>{s&&!t.location.includes(s)&&d({...t,location:[...t.location,s]})},placeholder:"ð Select locations...",className:"text-xs sm:text-base",showSearch:!0,style:{width:"100%"}},t.location.length),e.jsx("div",{className:`mt-2 border-2 border-gray-50 rounded-xl bg-gray-50/30 p-2 min-h-[50px] sm:min-h-[60px] max-h-[100px] overflow-y-auto custom-scrollbar-thin ${t.location.length===0?"flex items-center justify-center":""}`,children:t.location.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.location.map(s=>e.jsxs("div",{className:"inline-flex items-center gap-1.5 px-2 py-0.5
1sm:px-2.5 sm:py-1 rounded-lg text-[9px] sm:text-[10px] font-bold bg-white text-purple-700 border border-purple-100 shadow-sm transition-all animate-in fade-in zoom-in duration-200",children:[e.jsx(D,{size:10,className:"text-purple-400"})," ",s,e.jsx("button",{onClick:()=>d({...t,location:t.location.filter(a=>a!==s)}),className:"hover:text-red-500 cursor-pointer ml-1",children:"â"})]},s))}):e.jsx("span",{className:"text-[9px] sm:text-[10px] text-gray-400 italic",children:"No locations authorized"})})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"text-[11px] sm:text-sm font-bold text-gray-500 uppercase tracking-tighter",children:["System Role ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(_,{options:(x==null?void 0:x.filter(s=>!t.roles.includes(s)).map(s=>({value:s,label:s})))||[],value:t.roles.length>0?t.roles[0]:void 0,onChange:s=>d({...t,roles:s?[s]:[]}),className:"text-xs sm:text-base",placeholder:"Select assigned role...",showSearch:!0,allowClear:!0,style:{width:"100%"}})]})]})})]})};export{_e as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.