"use client"
import{a as K}from"./chunk-4DYBDVUA.mjs";import{a as D}from"./chunk-GVBIGY6N.mjs";import{a as B}from"./chunk-NWME2ANF.mjs";import{a as j}from"./chunk-MOH2SIKR.mjs";import{k as H}from"./chunk-QXYONDLF.mjs";import{a as V}from"./chunk-WMTXO7RT.mjs";import{a as $}from"./chunk-JOLDVN3E.mjs";import{a as F}from"./chunk-IHTRL6TU.mjs";import{a as L}from"./chunk-JW75YDRU.mjs";import{a as S}from"./chunk-IYJTXSAN.mjs";import{p as A,s as u}from"./chunk-QACSOQID.mjs";import{Command as h,CommandEmpty as ne,CommandInput as re,CommandItem as le}from"cmdk";import{ChevronDown as ie}from"lucide-react";import{isValidElement as ce,useCallback as me,useEffect as O,useRef as de,useState as p}from"react";import{Fragment as k,jsx as e,jsxs as l}from"react/jsx-runtime";function ue(o,s){return o===!0}function Ie({multiple:o,selected:s,setSelected:r,options:a,icon:f,placeholder:U="Select...",searchPlaceholder:Z="Search...",emptyState:M,createLabel:b,onCreate:x,buttonProps:i,shortcutHint:T,caret:q,side:G,open:J,onOpenChange:X,children:Y}){let I=ue(o,r),n=Array.isArray(s)?s:s?[s]:[],{isMobile:_}=B(),[ee,te]=p(!1),v=J??ee,g=X??te,[c,y]=p(""),[P,C]=p(!1),[z,oe]=p(void 0),[se,R]=p(!1),ae=t=>{var m;if(I){let N=n.some(({value:d})=>d===t.value);r(N?n.filter(({value:d})=>d!==t.value):[...n,t])}else r(n.length&&((m=n[0])==null?void 0:m.value)===t.value?null:t),g(!1)},E=me(t=>[...t].sort((m,N)=>{let d=n.some(w=>w.value===m.value),W=n.some(w=>w.value===N.value);return d&&!W?-1:!d&&W?1:0}),[n]);return O(()=>{P&&(oe(a&&E(a)),C(!1))},[P,a,E]),O(()=>{C(!0)},[a]),O(()=>{v||(y(""),C(!0))},[v]),e(K,{openPopover:v,setOpenPopover:g,align:"start",side:G,onWheel:t=>{t.stopPropagation()},content:e(j,{width:!_,height:!0,className:"rounded-[inherit]",style:{transform:"translateZ(0)"},transition:{ease:"easeInOut",duration:.1},children:l(h,{loop:!0,children:[l("div",{className:"flex items-center overflow-hidden rounded-t-lg border-b border-gray-200",children:[e(re,{placeholder:Z,value:c,onValueChange:y,className:"grow border-0 py-3 pl-4 pr-2 outline-none placeholder:text-gray-400 focus:ring-0 sm:text-sm",onKeyDown:t=>{(t.key==="Escape"||t.key==="Backspace"&&!c)&&(t.preventDefault(),t.stopPropagation(),g(!1))}}),T&&e("kbd",{className:"mr-2 hidden shrink-0 rounded bg-gray-200 px-2 py-0.5 text-xs font-light text-gray-500 md:block",children:T})]}),e(pe,{children:e(h.List,{className:u("flex w-full min-w-[100px] flex-col gap-1 p-1"),children:z!==void 0?l(k,{children:[z.map(t=>e(fe,{option:t,multiple:I,selected:n.some(({value:m})=>m===t.value),onSelect:()=>ae(t)},`${t.label}, ${t.value}`)),c.length>0&&x&&l(le,{className:u("flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm text-gray-700","data-[selected=true]:bg-gray-100"),onSelect:async()=>{R(!0),await(x==null?void 0:x(c))&&(y(""),g(!1)),R(!1)},children:[se?e(S,{className:"size-4 shrink-0"}):e(V,{className:"size-4 shrink-0"}),e("div",{className:"grow",children:(b==null?void 0:b(c))||`Create "${c}"`})]}),e(ne,{className:"flex h-12 items-center justify-center text-sm text-gray-500",children:M||"No matches"})]}):e(h.Loading,{children:e("div",{className:"flex h-12 items-center justify-center",children:e(S,{})})})})})]})}),children:e(H,{variant:"secondary",...i,className:u(i==null?void 0:i.className,"flex items-center gap-2"),textWrapperClassName:u(i==null?void 0:i.textWrapperClassName,"w-full flex items-center justify-start"),text:l(k,{children:[e("div",{className:"min-w-0 grow truncate text-left",children:Y||n.map(t=>t.label).join(", ")||U}),q&&e(ie,{className:"size-4 shrink-0 text-gray-400 transition-transform duration-75 group-data-[state=open]:rotate-180"})]}),icon:f?Q(f)?f:e(f,{className:"size-4"}):void 0})})}var pe=({children:o})=>{let s=de(null),{scrollProgress:r,updateScrollProgress:a}=D(s);return l(k,{children:[e("div",{className:"scrollbar-hide max-h-[min(50vh,190px)] w-screen overflow-y-scroll sm:w-auto",ref:s,onScroll:a,children:o}),e("div",{className:"pointer-events-none absolute bottom-0 left-0 hidden h-16 w-full bg-gradient-to-t from-white sm:block",style:{opacity:1-Math.pow(r,2)}})]})};function fe({option:o,onSelect:s,multiple:r,selected:a}){return l(h.Item,{className:u("flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm","data-[selected=true]:bg-gray-100"),onSelect:s,value:o.label+(o==null?void 0:o.value),children:[r&&e("div",{className:"shrink-0 text-gray-600",children:a?e($,{className:"size-4 text-gray-600"}):e(F,{className:"size-4 text-gray-400"})}),l("div",{className:"flex grow items-center gap-1",children:[o.icon&&e("span",{className:"shrink-0 text-gray-600",children:Q(o.icon)?o.icon:e(o.icon,{className:"h-4 w-4"})}),A(o.label,48)]}),!r&&a&&e(L,{className:"size-4 shrink-0 text-gray-600"})]})}var Q=o=>ce(o);export{Ie as a};
