import{o as e}from"./rolldown-runtime-BTPm5ob3.js";import{i as t,r as n}from"./animations-BBry1XJJ.js";import{Ir as r,Qt as i,jr as a}from"./react-core-DZu2Qwle.js";import{J as o,O as s,X as c,Y as l,ct as u,it as d,q as f}from"./index-OXd4Aieb.js";var p=e(n(),1),m=t();function h({options:e,value:t,onChange:n,placeholder:h=`Select an option...`,className:g,onSearch:_,searchPlaceholder:v=`Search...`,label:y}){let[b,x]=p.useState(!1),[S,C]=p.useState(``),w=e=>{C(e),_&&_(e)},T=_?e:e.filter(e=>(e.label||``).toLowerCase().includes(S.toLowerCase())),E=e=>{n(e),x(!1)},D=e.find(e=>e.value===t),O=g?.includes(`flex-1`);return(0,m.jsxs)(`div`,{className:u(`space-y-2 w-full`,O&&`flex-1`),children:[y&&(0,m.jsx)(d,{className:`text-sm font-semibold`,children:y}),(0,m.jsxs)(o,{open:b,onOpenChange:x,children:[(0,m.jsx)(c,{asChild:!0,children:(0,m.jsxs)(`div`,{role:`button`,tabIndex:0,className:u(`flex h-8 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-1.5 text-xs ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer`,g?.replace(`flex-1`,``)),onPointerDown:e=>e.stopPropagation(),onClick:()=>x(!b),children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2 truncate flex-1`,children:[D?.icon&&(0,m.jsx)(`span`,{className:`shrink-0 me-2`,children:D.icon}),(0,m.jsx)(`span`,{className:u(`truncate`,!D&&`text-muted-foreground`),children:D?D.label:h})]}),(0,m.jsx)(a,{className:`h-4 w-4 shrink-0 opacity-50 ms-2`})]})}),(0,m.jsx)(l,{className:`p-0 z-[999999]`,align:`start`,side:`bottom`,sideOffset:4,style:{width:`var(--radix-popover-trigger-width)`},children:(0,m.jsxs)(`div`,{className:`flex flex-col bg-white border rounded-md shadow-xl overflow-hidden`,children:[(0,m.jsx)(`div`,{className:`w-full`,children:(0,m.jsx)(s,{label:`Search`,placeholder:v,value:S,onChange:w,icon:i,className:`bg-transparent border-none focus-visible:ring-0`,labelHidden:!0})}),(0,m.jsx)(f,{className:`max-h-60 overflow-y-auto p-1`,children:T.length===0?(0,m.jsx)(`div`,{className:`p-4 text-center text-sm text-muted-foreground`,children:`No results found.`}):(0,m.jsx)(`div`,{className:`space-y-1`,children:T.map(e=>(0,m.jsxs)(`div`,{className:u(`flex items-start gap-2 rounded-sm px-2 py-2 cursor-pointer transition-colors text-sm font-medium`,e.disabled?`opacity-60 cursor-not-allowed bg-slate-50 text-slate-400`:`hover:bg-accent hover:text-accent-foreground`,t===e.value&&`bg-accent/50 text-primary`),onClick:()=>{e.disabled||E(e.value)},children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0`,children:[e.icon&&(0,m.jsx)(`span`,{className:`shrink-0 self-center me-2`,children:e.icon}),(0,m.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,m.jsx)(`span`,{className:`truncate block font-semibold text-slate-700`,children:e.label}),e.description&&(0,m.jsx)(`span`,{className:u(`text-[11px] leading-normal mt-0.5 whitespace-normal break-words`,e.disabled?`text-rose-500 font-medium`:`text-muted-foreground font-normal`),children:e.description})]})]}),t===e.value&&(0,m.jsx)(r,{className:`h-4 w-4 shrink-0 self-center`})]},e.value))})})]})})]})]})}export{h as t};