import{j as e}from"./query-PJ0ZdjbV.js";import{a as p}from"./vendor-CWhr2lg4.js";import{c4 as v,c5 as w,B as _,ap as x,c6 as b,c7 as S,ar as E,c8 as k,c9 as L,ca as P,cb as $,cc as B,C as O}from"./index-BSPIaiZU.js";import{a as V}from"./core-hr.api-MChaGqvv.js";import{C as z}from"./date-range-picker-BB0TgAn8.js";function T({value:h,onValueChange:f,userId:o,selectedLabel:u,placeholder:j="Select employee",disabled:y=!1,className:C,status:l}){var d;const[c,i]=p.useState(!1),[m,N]=p.useState(""),{data:n,isLoading:g}=V({page_size:200,search:m||void 0,...l&&{status:l}}),r=(n==null?void 0:n.results)??[],a=h||(o?((d=r.find(s=>s.user===o))==null?void 0:d.id)??"":""),t=r.find(s=>s.id===a);return e.jsxs(v,{open:c,onOpenChange:i,children:[e.jsx(w,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":c,disabled:y,className:x("w-full justify-between font-normal h-9",!a&&"text-muted-foreground",C),children:[e.jsx("span",{className:"truncate",children:t?`${t.first_name} ${t.last_name} (${t.employee_id})`:a&&u||j}),e.jsx(z,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(b,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(S,{shouldFilter:!1,children:[e.jsxs("div",{className:"flex items-center border-b px-3",children:[e.jsx(E,{className:"mr-2 h-3.5 w-3.5 shrink-0 opacity-50"}),e.jsx(k,{placeholder:"Search by name or code...",value:m,onValueChange:N,className:"border-0 focus:ring-0"})]}),e.jsxs(L,{children:[e.jsx(P,{children:g?"Loading...":"No employees found."}),e.jsx($,{children:r.map(s=>e.jsxs(B,{value:s.id,onSelect:()=>{f(s.id),i(!1)},className:"flex items-center gap-2",children:[e.jsx(O,{className:x("h-3.5 w-3.5 shrink-0",a===s.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"text-[13px] font-medium text-slate-900",children:[s.first_name," ",s.last_name]}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:s.employee_id}),s.department_name&&e.jsxs("span",{className:"ml-1.5 text-[11px] text-slate-400",children:["· ",s.department_name]})]})]},s.id))})]})]})})]})}export{T as E};
