import{a as e,n as t,t as n}from"./jsx-runtime-B-hcVAMW.js";import{E as r,j as i,k as a,z as o}from"./index-DyQEyT-0.js";import{t as s}from"./Badge-BGqYAYKM.js";import{t as c}from"./EmptyState-BCP63FMk.js";import{t as l}from"./ErrorState-BkSpMSl3.js";import{n as u}from"./hooks-GZ9g_2ty.js";import{t as d}from"./statusTones-BsGMHvqm.js";var f=e(t(),1),p=n();function m(){let{can:e}=a(),[t,n]=(0,f.useState)(``),[m,h]=(0,f.useState)(``),[g,_]=(0,f.useState)(1),{data:v,isPending:y,error:b,refetch:x,isPlaceholderData:S}=u({search:t||void 0,status:m||void 0,page:g});if(y)return(0,p.jsx)(r,{label:`Loading agents`});if(b)return(0,p.jsx)(l,{error:b,onRetry:()=>x()});let{agents:C,meta:w}=v,T=w?.last_page??1;return(0,p.jsxs)(`div`,{className:`space-y-6`,children:[(0,p.jsxs)(`header`,{className:`flex flex-wrap items-end justify-between gap-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`h1`,{className:`text-xl font-semibold text-slate-900`,children:`Agents`}),(0,p.jsxs)(`p`,{className:`mt-1 text-sm text-slate-500`,children:[w?.total??0,` agent`,w?.total===1?``:`s`,` within your access scope.`]})]}),e(`agent.create`)&&(0,p.jsx)(o,{to:`/app/agents/new`,children:(0,p.jsx)(i,{children:`Register agent`})})]}),(0,p.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,p.jsx)(`input`,{type:`search`,value:t,placeholder:`Search name, code, phone or territory`,"aria-label":`Search agents`,onChange:e=>{n(e.target.value),_(1)},className:`w-full max-w-sm rounded-lg border-0 px-3 py-2 text-sm ring-1 ring-inset ring-slate-300 focus:ring-2 focus:ring-brand-600`}),(0,p.jsxs)(`select`,{value:m,"aria-label":`Filter by status`,onChange:e=>{h(e.target.value),_(1)},className:`rounded-lg border-0 py-2 pl-3 pr-8 text-sm ring-1 ring-inset ring-slate-300 focus:ring-2 focus:ring-brand-600`,children:[(0,p.jsx)(`option`,{value:``,children:`All statuses`}),(w?.statuses??[]).map(e=>(0,p.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),C.length===0?(0,p.jsx)(c,{title:`No agents found`,description:`Adjust the filters, or register a new agent.`}):(0,p.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-slate-200 bg-white transition-opacity ${S?`opacity-60`:``}`,children:(0,p.jsxs)(`table`,{className:`min-w-full divide-y divide-slate-200 text-sm`,children:[(0,p.jsx)(`thead`,{className:`bg-slate-50 text-left text-xs font-medium uppercase tracking-wide text-slate-500`,children:(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Agent`}),(0,p.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Phone`}),(0,p.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Territory`}),(0,p.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Branch`}),(0,p.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Target`}),(0,p.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Status`})]})}),(0,p.jsx)(`tbody`,{className:`divide-y divide-slate-100`,children:C.map(e=>(0,p.jsxs)(`tr`,{className:`hover:bg-slate-50`,children:[(0,p.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,p.jsx)(o,{to:`/app/agents/${e.id}`,className:`font-medium text-slate-900 hover:text-brand-700`,children:e.name}),(0,p.jsx)(`p`,{className:`font-mono text-xs text-slate-500`,children:e.agent_code})]}),(0,p.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.phone}),(0,p.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.territory??`—`}),(0,p.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.branch?.name??`—`}),(0,p.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.monthly_target??`—`}),(0,p.jsx)(`td`,{className:`px-4 py-3`,children:(0,p.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,p.jsx)(s,{tone:d[e.status],children:e.status_label}),e.contract_expired&&(0,p.jsx)(s,{tone:`warning`,children:`Contract expired`})]})})]},e.id))})]})}),T>1&&(0,p.jsxs)(`nav`,{className:`flex items-center justify-between`,"aria-label":`Pagination`,children:[(0,p.jsx)(i,{variant:`secondary`,disabled:g<=1,onClick:()=>_(e=>e-1),children:`Previous`}),(0,p.jsxs)(`span`,{className:`text-sm text-slate-500`,children:[`Page `,w?.current_page??g,` of `,T]}),(0,p.jsx)(i,{variant:`secondary`,disabled:g>=T,onClick:()=>_(e=>e+1),children:`Next`})]})]})}export{m as default};