import{j as s}from"./query-PJ0ZdjbV.js";import{a as i}from"./vendor-CWhr2lg4.js";import{c4 as k,c5 as P,B,ap as u,c6 as E,c7 as O,ar as S,c8 as T,c9 as A,ca as D,cb as F,cc as I,C as M,aT as R}from"./index-BSPIaiZU.js";import{B as $}from"./badge-C34iUAiA.js";import{u as q}from"./async-select-BUbwdJEZ.js";import{C as G}from"./date-range-picker-BB0TgAn8.js";function J({value:a,onValueChange:f,options:l,onSearch:n,selectedLabels:o,isLoading:j=!1,placeholder:g="Select...",searchPlaceholder:C="Search...",emptyText:N="No results found.",disabled:m=!1,className:w}){const[d,b]=i.useState(!1),[c,v]=i.useState(""),x=q(c,250);i.useEffect(()=>{n==null||n(x)},[x]);function h(e){f(a.includes(e)?a.filter(t=>t!==e):[...a,e])}function p(e){var t;return((t=l.find(r=>r.value===e))==null?void 0:t.label)??(o==null?void 0:o[e])??e}const y=n?l:l.filter(e=>{var r;const t=c.trim().toLowerCase();return t?e.label.toLowerCase().includes(t)||(((r=e.hint)==null?void 0:r.toLowerCase().includes(t))??!1):!0});return s.jsxs("div",{className:w,children:[s.jsxs(k,{open:d,onOpenChange:b,children:[s.jsx(P,{asChild:!0,children:s.jsxs(B,{variant:"outline",role:"combobox","aria-expanded":d,disabled:m,className:u("w-full justify-between font-normal h-9",a.length===0&&"text-muted-foreground"),children:[s.jsx("span",{className:"truncate",children:a.length===0?g:`${a.length} selected`}),s.jsx(G,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),s.jsx(E,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:s.jsxs(O,{shouldFilter:!1,children:[s.jsxs("div",{className:"flex items-center border-b px-3",children:[s.jsx(S,{className:"mr-2 h-3.5 w-3.5 shrink-0 opacity-50"}),s.jsx(T,{placeholder:C,value:c,onValueChange:v,className:"border-0 focus:ring-0"})]}),s.jsxs(A,{children:[s.jsx(D,{children:j?"Loading...":N}),s.jsx(F,{children:y.map(e=>s.jsxs(I,{value:e.value,onSelect:()=>h(e.value),className:"flex items-center gap-2",children:[s.jsx(M,{className:u("h-3.5 w-3.5 shrink-0",a.includes(e.value)?"opacity-100":"opacity-0")}),s.jsxs("span",{className:"flex-1 min-w-0 truncate text-[13px] text-slate-900",children:[e.label,e.hint&&s.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:e.hint})]})]},e.value))})]})]})})]}),a.length>0&&s.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:a.map(e=>s.jsxs($,{variant:"secondary",className:"gap-1 pr-1 font-normal",children:[p(e),!m&&s.jsx("button",{type:"button",onClick:()=>h(e),className:"rounded-sm text-slate-400 hover:text-slate-700","aria-label":`Remove ${p(e)}`,children:s.jsx(R,{className:"h-3 w-3"})})]},e))})]})}export{J as A};
