import{a as e,n as t,t as n}from"./jsx-runtime-B-hcVAMW.js";import{E as r,j as i,z as a}from"./index-DyQEyT-0.js";import{t as o}from"./Badge-BGqYAYKM.js";import{t as s}from"./EmptyState-BCP63FMk.js";import{t as c}from"./ErrorState-BkSpMSl3.js";import{a as l,t as u}from"./statusTones-B9XiNm84.js";var d=e(t(),1),f=n();function p(){let[e,t]=(0,d.useState)(``),[n,p]=(0,d.useState)(!0),[m,h]=(0,d.useState)(``),[g,_]=(0,d.useState)(1),{data:v,isPending:y,error:b,refetch:x,isPlaceholderData:S}=l({search:m||void 0,status:e||void 0,open_only:n||void 0,page:g});if(y)return(0,f.jsx)(r,{label:`Loading requisitions`});if(b)return(0,f.jsx)(c,{error:b,onRetry:()=>x()});let{requisitions:C,meta:w}=v,T=w?.last_page??1;return(0,f.jsxs)(`div`,{className:`space-y-6`,children:[(0,f.jsxs)(`header`,{children:[(0,f.jsx)(`h1`,{className:`text-xl font-semibold text-slate-900`,children:`Employer requisitions`}),(0,f.jsxs)(`p`,{className:`mt-1 text-sm text-slate-500`,children:[w?.total??0,` requirement`,w?.total===1?``:`s`,` submitted from the website.`]})]}),(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,f.jsx)(`input`,{type:`search`,value:m,placeholder:`Search company, number or contact`,"aria-label":`Search requisitions`,onChange:e=>{h(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,f.jsxs)(`select`,{value:e,"aria-label":`Filter by status`,onChange:e=>{t(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,f.jsx)(`option`,{value:``,children:`All statuses`}),(w?.statuses??[]).map(e=>(0,f.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-slate-600`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>{p(e.target.checked),_(1)},className:`size-4 rounded border-slate-300 text-brand-600 focus:ring-brand-600`}),`Needing attention`]})]}),C.length===0?(0,f.jsx)(s,{title:`No requisitions`,description:`Requirements submitted through the website appear here.`}):(0,f.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-slate-200 bg-white transition-opacity ${S?`opacity-60`:``}`,children:(0,f.jsxs)(`table`,{className:`min-w-full divide-y divide-slate-200 text-sm`,children:[(0,f.jsx)(`thead`,{className:`bg-slate-50 text-left text-xs font-medium uppercase tracking-wide text-slate-500`,children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Employer`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Country`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Workers`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Submitted`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Assigned`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Status`})]})}),(0,f.jsx)(`tbody`,{className:`divide-y divide-slate-100`,children:C.map(e=>(0,f.jsxs)(`tr`,{className:`hover:bg-slate-50`,children:[(0,f.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,f.jsx)(a,{to:`/app/requisitions/${e.id}`,className:`font-medium text-slate-900 hover:text-brand-700`,children:e.company_name}),(0,f.jsx)(`p`,{className:`font-mono text-xs text-slate-500`,children:e.requisition_no})]}),(0,f.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.country}),(0,f.jsxs)(`td`,{className:`px-4 py-3 text-slate-600`,children:[e.total_workers??`—`,(0,f.jsxs)(`span`,{className:`ml-1 text-xs text-slate-400`,children:[`(`,e.positions?.length??0,` roles)`]})]}),(0,f.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.submitted_at?new Date(e.submitted_at).toLocaleDateString():`—`}),(0,f.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:e.assignee??`—`}),(0,f.jsx)(`td`,{className:`px-4 py-3`,children:(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,f.jsx)(o,{tone:u[e.status],children:e.status_label}),e.urgency!==`standard`&&(0,f.jsx)(o,{tone:`danger`,children:e.urgency})]})})]},e.id))})]})}),T>1&&(0,f.jsxs)(`nav`,{className:`flex items-center justify-between`,"aria-label":`Pagination`,children:[(0,f.jsx)(i,{variant:`secondary`,disabled:g<=1,onClick:()=>_(e=>e-1),children:`Previous`}),(0,f.jsxs)(`span`,{className:`text-sm text-slate-500`,children:[`Page `,w?.current_page??g,` of `,T]}),(0,f.jsx)(i,{variant:`secondary`,disabled:g>=T,onClick:()=>_(e=>e+1),children:`Next`})]})]})}export{p as default};