import{d as z,w as U,b as a,l as K,u as c,m as h,j as v,D as g,c as n,A as m,k as i,I as A,z as p,F as V,y as B,e as o,r as L}from"./graphExplorationMessages.js";import{a as Q,ap as G,aq as H,F as J,ar as R,o as W,bb as X}from"./index.js";const Y={key:0,class:"text-muted-foreground"},Z={key:1},ee={class:"p-2 border-b"},te={class:"p-2"},se={key:0,class:"dku-icon-checkmark-12 text-primary-foreground"},le={class:"flex-1 min-w-0"},ae={class:"text-sm font-medium"},ne={key:0,class:"px-2 py-1.5 text-xs font-semibold text-muted-foreground"},oe=["onClick"],re={key:0,class:"dku-icon-checkmark-12 text-primary-foreground"},de={key:0,class:"p-1 rounded-full bg-[#D96D9C] text-white flex-shrink-0 h-6 w-6 flex items-center justify-center"},ie={class:"flex-1 min-w-0"},ce={class:"text-sm font-medium"},ue={key:0,class:"text-xs text-muted-foreground truncate"},me={key:1,class:"px-2 py-4 text-center text-sm text-muted-foreground"},he=z({__name:"SearchableMultiSelect",props:{modelValue:{},options:{},placeholder:{},itemLabel:{},searchPlaceholder:{},emptyMessage:{},disabled:{type:Boolean,default:!1},triggerClass:{type:[Boolean,null,String,Object,Array],default:"admin-select-trigger admin-dropdown-trigger w-full justify-between"},contentClass:{type:[Boolean,null,String,Object,Array],default:"w-[420px] p-0"},align:{default:"start"}},emits:["update:modelValue"],setup(f,{emit:M}){const{t:u}=Q(),l=f,S=o(()=>l.placeholder??u("select_an_option")),D=o(()=>l.searchPlaceholder??u("search.placeholder")),I=o(()=>l.emptyMessage??u("no_options_found")),y=M,_=L(""),k=L(!1);U(k,t=>{t||(_.value="")});const O=o(()=>new Set(l.modelValue)),x=o(()=>l.options.map(t=>t.id)),$=o(()=>new Set(x.value)),E=o(()=>l.modelValue.filter(t=>$.value.has(t)).length),w=o(()=>x.value.length>0),b=o(()=>w.value&&E.value===x.value.length),F=o(()=>l.modelValue.length===0?S:l.modelValue.length===1?u("item_selected.count.one"):u("item_selected.count.other.template",{itemsCount:l.modelValue.length})),j=o(()=>{const t=_.value.toLowerCase().trim();return t?l.options.filter(e=>{var C;const s=e.label.toLowerCase(),d=e.id.toLowerCase(),r=((C=e.description)==null?void 0:C.toLowerCase())??"";return s.includes(t)||d.includes(t)||r.includes(t)}):l.options}),N=o(()=>{const t={},e=[];return j.value.forEach(s=>{const d=s.group??"";t[d]||(t[d]=[],e.push(d)),t[d].push(s)}),e.map(s=>({label:s,options:t[s]}))}),P=o(()=>j.value.length>0);function T(t){const e=l.modelValue,s=e.includes(t)?e.filter(d=>d!==t):[...e,t];y("update:modelValue",s)}function q(){if(!w.value)return;if(b.value){y("update:modelValue",l.modelValue.filter(e=>!$.value.has(e)));return}const t=new Set(l.modelValue);x.value.forEach(e=>t.add(e)),y("update:modelValue",[...t])}return(t,e)=>(a(),K(c(G),{open:k.value,"onUpdate:open":e[3]||(e[3]=s=>k.value=s)},{default:h(()=>[v(c(H),{"as-child":""},{default:h(()=>[v(c(J),{variant:"outline",disabled:f.disabled,class:g(f.triggerClass)},{default:h(()=>[f.modelValue.length===0?(a(),n("span",Y,m(S.value),1)):(a(),n("span",Z,m(F.value),1)),e[4]||(e[4]=i("i",{class:"dku-icon-caret-down-12 ml-2"},null,-1))]),_:1},8,["disabled","class"])]),_:1}),v(c(R),{class:g(f.contentClass),align:f.align},{default:h(()=>[i("div",ee,[v(c(W),{modelValue:_.value,"onUpdate:modelValue":e[0]||(e[0]=s=>_.value=s),placeholder:D.value,class:"h-8",onClick:e[1]||(e[1]=A(()=>{},["stop"])),onKeydown:e[2]||(e[2]=A(()=>{},["stop"]))},null,8,["modelValue","placeholder"])]),v(c(X),{class:"max-h-[300px]"},{default:h(()=>[i("div",te,[w.value?(a(),n("div",{key:0,onClick:q,class:"mb-1 flex w-full items-center gap-2 px-2 py-2 cursor-pointer hover:bg-accent rounded-md"},[i("div",{class:g(["flex items-center justify-center w-4 h-4 border rounded flex-shrink-0 border-input",b.value&&"bg-black"])},[b.value?(a(),n("i",se)):p("",!0)],2),i("div",le,[i("div",ae,m(b.value?c(u)("unselect_all"):c(u)("select_all")),1)])])):p("",!0),(a(!0),n(V,null,B(N.value,(s,d)=>(a(),n(V,{key:s.label||`group-${d}`},[s.label?(a(),n("div",ne,m(s.label),1)):p("",!0),(a(!0),n(V,null,B(s.options,r=>(a(),n("div",{key:r.id,onClick:C=>T(r.id),class:"flex items-center gap-2 px-2 py-2 cursor-pointer hover:bg-accent rounded-md"},[i("div",{class:g(["flex items-center justify-center w-4 h-4 border rounded flex-shrink-0 border-input",O.value.has(r.id)&&"bg-black"])},[O.value.has(r.id)?(a(),n("i",re)):p("",!0)],2),r.iconClass?(a(),n("div",de,[i("i",{class:g(r.iconClass)},null,2)])):p("",!0),i("div",ie,[i("div",ce,m(r.label),1),r.description?(a(),n("div",ue,m(r.description),1)):p("",!0)])],8,oe))),128))],64))),128)),P.value?p("",!0):(a(),n("div",me,m(I.value),1))])]),_:1})]),_:1},8,["class","align"])]),_:1},8,["open"]))}});export{he as _};
