1import{r as o,u as D,j as t,S as C,I as S,k as b,B as u,L as _,ez as B,dO as K,s as g}from"./index-hL3pcTef.js";import{b as O}from"./public.queries-BQ4rAO2p.js";import{n as R,o as T}from"./admin.mutations-BvTTxrF1.js";import{D as U}from"./DeleteConfirmModal-C9Fy8C2n.js";import{d as V}from"./file.service-gzlP3vSC.js";import{i as w}from"./isActiveEnabled-CMsynq6w.js";import{T as q}from"./index-BcWpjjeV.js";import{R as G}from"./PlusOutlined-BW1yN58X.js";import{F as H,P as J}from"./Table-ByPjUBsP.js";import{S as Q}from"./index-C1N5wVkR.js";import"./public.mutations-BNuhp7Yl.js";import"./styleChecker-C7z56Tbj.js";import"./addEventListener-dXBIMZpu.js";import"./index-XUTl3fJi.js";import"./useBubbleLock-C2OM8qLP.js";import"./index-CbIDiTdO.js";import"./Dropdown-WwCtKhvr.js";import"./index-Dc7QU0W2.js";import"./useForm-CRGMdtfF.js";import"./index-waoBxi_t.js";const{Option:p}=b,W=n=>{if(!n||typeof n!="string"||n.includes("default"))return"";try{return new URL(n).pathname.replace(/^\/+/,"")}catch{return n}},xe=()=>{const[n,h]=o.useState({agentId:"",agentName:"",location:"",status:"all"}),[r,f]=o.useState(1),[s,l]=o.useState(null),c=10,x=D(),{data:N=[],isLoading:I}=O(),y=R(),k=T(),L=o.useMemo(()=>(N||[]).map(e=>{var a,i;return{...e,firstName:e.firstName||((a=e.user)==null?void 0:a.firstName)||"",lastName:e.lastName||((i=e.user)==null?void 0:i.lastName)||"",location:e.location||"",phoneExtension:e.phoneExtension||""}}),[N]),E=async()=>{if(!s)return;const e=W(s.profilePicture);try{if(e)try{await V(e)}catch(a){g.warning("Agent deleted, but failed to delete profile image from S3."),console.error("Failed to delete agent profile image from S3:",a)}await y.mutateAsync(s.id),l(null)}catch(a){g.error((a==null?void 0:a.message)||"Failed to delete agent.")}},z=async(e,a)=>{try{await k.mutateAsync({agentId:e,isActive:a})}catch(i){g.error((i==null?void 0:i.message)||"Error updating status.")}},d=(e,a)=>{h(i=>({...i,[e]:a})),f(1)},A=L.filter(e=>{var v;const a=n.agentId?e.id.toString().includes(n.agentId):!0,i=`${e.firstName||""} ${e.lastName||""}`.toLowerCase(),m=n.agentName?i.includes(n.agentName.toLowerCase()):!0,P=n.location?(v=e.location)==null?void 0:v.toLowerCase().includes(n.location.toLowerCase()):!0,j=w(e.isActive),$=n.status==="all"?!0:n.status==="active"?j:!j;return a&&m&&P&&$}),F=A.slice((r-1)*c,r*c),M=[{title:"Agent",dataIndex:"full_name",key:"full_name",render:(e,a)=>{const i=`${a.firstName||""} ${a.lastName||""}`.trim(),m=`/ca/${i.replace(/\s+/g,"-").toLowerCase()}`;return t.jsx(_,{to:m,className:"!text-primary-500 underline",children:i||"No Name"})}},{title:"Location",dataIndex:"location",key:"location"},{title:"Phone Extension",dataIndex:"phoneExtension",key:"phoneExtension"},{title:"Status",dataIndex:"isActive",key:"isActive",render:(e,a)=>t.jsx(Q,{checked:w(a.isActive),onChange:i=>z(a.id,i),checkedChildren:"Active",unCheckedChildren:"Inactive"})},{title:"Actions",key:"actions",render:(e,a)=>t.jsxs(C,{children:[t.jsx(u,{size:"large",type:"text",className:"admin-action-btn admin-action-edit",icon:t.jsx(B,{className:"admin-action-icon"}),onClick:()=>x(`/admin-dashboard/agent/edit/${a.id}`)}),t.jsx(u,{size:"large",type:"text",className:"admin-action-btn admin-action-delete",icon:t.jsx(K,{className:"admin-action-icon"}),onClick:()=>l(a)})]})}];return t.jsxs("div",{style:{padding:"24px"},children:[t.jsx("div",{className:"mb-4",children:t.jsx(q.Title,{level:3,children:"Agent Management"})}),t.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[t.jsxs(C,{wrap:!0,children:[t.jsx(S,{size:"large",placeholder:"Agent Name",value:n.agentName,onChange:e=>d("agentName",e.target.value),style:{width:200}}),t.jsx(S,{size:"large",placeholder:"Location",value:n.location,onChange:e=>d("location",e.target.value),style:{width:200}}),t.jsxs(b,{size:"large",placeholder:"Status",defaultValue:"all",value:n.status,onChange:e=>d("status",e),style:{width:160},children:[t.jsx(p,{value:"all",children:"All"}),t.jsx(p,{value:"active",children:"Active"}),t.jsx(p,{value:"inactive",children:"Inactive"})]})]}),t.jsx(u,{size:"large",type:"primary",icon:t.jsx(G,{}),onClick:()=>x("/admin-dashboard/agent/add"),children:"Add Agent"})]}),t.jsx(H,{columns:M,dataSource:F,rowKey:"id",loading:I,pagination:!1,bordered:!0}
1),t.jsx("div",{className:"mt-4 flex justify-center",children:t.jsx(J,{current:r,pageSize:c,total:A.length,onChange:e=>f(e),showSizeChanger:!1})}),t.jsx(U,{open:!!s,title:"Delete this agent?",itemName:`${(s==null?void 0:s.firstName)||""} ${(s==null?void 0:s.lastName)||""}`.trim()||(s==null?void 0:s.id),entityLabel:"agent",description:"This action cannot be undone.",onCancel:()=>l(null),onConfirm:E,loading:y.isPending})]})};export{xe 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.