import{r as t,j as e,P as B,y as F,B as z,w as N,z as D,E as G}from"./index-C9vqJYWU.js";import{C as H,e as U,f as q,g as J,h as K,i as M}from"./command-CfddNxWu.js";import{C as Q}from"./chevrons-up-down-BHMtvqij.js";import{L as S}from"./label-CwKg3qNE.js";function $({value:u,onValueChange:_,placeholder:L="Select option...",searchPlaceholder:E="Search...",emptyMessage:I="No results found.",disabled:k=!1,className:P,options:T,onSearch:l,debounceMs:g=300,minSearchLength:p=0,initialOptions:a=[],isLoading:R=!1}){const[r,j]=t.useState(!1),[x,w]=t.useState(""),[h,o]=t.useState(a),[m,y]=t.useState(!1),[b,C]=t.useState(a.length>0),[f,i]=t.useState(!1),c=t.useRef(null),d=T||h,n=!!l,V=d.find(s=>s.value===u);t.useEffect(()=>{a.length>0&&(o(a),C(!0))},[a]),t.useEffect(()=>{if(!(!n||!r)){if(c.current&&clearTimeout(c.current),x.length<p){o(a.length>0?a:h);return}return c.current=setTimeout(async()=>{y(!0);try{const s=await l(x);o(s)}catch(s){console.error("Search error:",s)}finally{y(!1)}},g),()=>{c.current&&clearTimeout(c.current)}}},[x,n,l,r,g,p]),t.useEffect(()=>{r||(w(""),n&&a.length>0&&o(a))},[r,n,a]),t.useEffect(()=>{r&&n&&!b&&!m&&!f&&(h.length===0&&a.length===0&&i(!0),C(!0),l("").then(A=>{o(A),i(!1)}).catch(()=>{i(!1)}))},[r,n,b,m,f,l,h.length,a.length]);const v=R||m||f;return e.jsxs(B,{open:r,onOpenChange:j,children:[e.jsx(F,{asChild:!0,children:e.jsxs(z,{variant:"outline",role:"combobox","aria-expanded":r,disabled:k,className:N("w-full justify-between font-normal","h-11 rounded-[30px] bg-background dark:bg-card px-4 py-2.5 text-base text-foreground","shadow-[0px_4px_20px_rgba(0,0,0,0.08)] dark:shadow-[0px_4px_20px_rgba(0,0,0,0.3)]","focus:outline-none focus:shadow-[0px_4px_20px_rgba(0,0,0,0.16)] dark:focus:shadow-[0px_4px_20px_rgba(0,0,0,0.5)]","transition-shadow duration-200","disabled:cursor-not-allowed disabled:opacity-50",!u&&"text-muted-foreground",P),children:[V?.label||L,e.jsx(Q,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(D,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(H,{shouldFilter:!n,children:[e.jsx(U,{placeholder:E,value:x,onValueChange:w,className:"h-10"}),e.jsx(q,{children:v&&d.length===0?e.jsxs("div",{className:"flex items-center justify-center py-6",children:[e.jsx(S,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading..."})]}):e.jsxs(e.Fragment,{children:[d.length===0?e.jsx(J,{children:I}):e.jsx(K,{children:d.map(s=>e.jsxs(M,{value:n?s.value:s.label,onSelect:()=>{_(s.value===u?"":s.value),j(!1)},children:[e.jsx(G,{className:N("mr-2 h-4 w-4",u===s.value?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.label}),s.description&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.description})]})]},s.value))}),v&&d.length>0&&e.jsxs("div",{className:"flex items-center justify-center py-2 border-t",children:[e.jsx(S,{className:"h-3 w-3 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"Searching..."})]})]})})]})})]})}export{$ as S};
