import{a as e,t}from"./react-DK-MTtD8.js";import{s as n,t as r}from"./utils-CXcsdpX-.js";import{t as i}from"./chevron-down-BFQhmj4o.js";import{Uo as a,_o as o}from"./index-Ct5uU080.js";var s=e(t(),1),c=n();function l({value:e,onValueChange:t,options:n,placeholder:l=`Select...`,disabled:u,id:d,className:f,emptyMessage:p}){let[m,h]=(0,s.useState)(!1),[g,_]=(0,s.useState)(``),v=(0,s.useRef)(null),y=(0,s.useRef)(null),b=(0,s.useMemo)(()=>{if(!g)return n;let e=g.toLowerCase();return n.filter(t=>t.label.toLowerCase().includes(e))},[n,g]),x=n.find(t=>t.value===e)?.label;return(0,s.useEffect)(()=>{m&&(_(``),setTimeout(()=>v.current?.focus(),0))},[m]),(0,s.useEffect)(()=>{if(!m)return;let e=e=>{y.current&&!y.current.contains(e.target)&&h(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[m]),(0,c.jsxs)(`div`,{ref:y,className:`relative`,children:[(0,c.jsxs)(`button`,{type:`button`,id:d,disabled:u,role:`combobox`,"aria-expanded":m,onClick:()=>!u&&h(!m),className:r(`flex w-full items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm h-9 whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-primary focus-visible:ring-[3px] focus-visible:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30 dark:hover:bg-input/50`,!x&&`text-muted-foreground`,f),children:[(0,c.jsx)(`span`,{className:`truncate`,children:x||l}),(0,c.jsx)(i,{className:`size-4 shrink-0 opacity-50`})]}),m&&(0,c.jsxs)(`div`,{className:`absolute top-full left-0 z-[200] mt-1 w-full rounded-lg border border-border/60 bg-popover text-popover-foreground shadow-lg animate-in fade-in-0 zoom-in-95`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 px-3 py-2`,children:[(0,c.jsx)(o,{className:`size-4 shrink-0 text-muted-foreground`}),(0,c.jsx)(`input`,{ref:v,value:g,onChange:e=>_(e.target.value),placeholder:`Search...`,className:`flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`})]}),(0,c.jsx)(`div`,{className:`overflow-y-auto max-h-56`,children:b.length===0?(0,c.jsx)(`div`,{className:`py-4 text-center text-sm text-muted-foreground`,children:n.length===0?p||`No options available`:`No results found`}):b.map(n=>(0,c.jsxs)(`button`,{type:`button`,className:r(`relative flex w-full cursor-pointer items-center gap-2 py-2.5 pr-8 pl-3 text-sm border-b border-border/40 last:border-b-0 transition-colors hover:bg-primary/10 hover:text-primary`,e===n.value&&`bg-primary text-primary-foreground`),onClick:()=>{t?.(n.value),h(!1)},children:[(0,c.jsx)(`span`,{className:`truncate`,children:n.label}),e===n.value&&(0,c.jsx)(`span`,{className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,c.jsx)(a,{className:`size-4`})})]},n.value))})]})]})}export{l as t};