import{_ as X,a as m,E as Y,y as I,m as g,o as i,c as n,e as L,g as N,d as r,H as w,O as R,s as T,t as f,w as _,aE as E,h as y,n as S,u as q,I as Z,f as x,r as ee,ae as le,aF as te,p as se,i as ae}from"./index-4e8c1b57.js";const ue=s=>(se("data-v-0a0c88ec"),s=s(),ae(),s),ie={class:"multiselect"},ne={key:0,class:"multiselect-tags"},oe={class:"multiselect-tag-text"},de=["onClick"],re=["id"],ce=["id","disabled"],ve={key:2,class:"multiselect-single-label"},me={class:"multiselect-single-label-text"},fe={key:3,class:"multiselect-multiple-label"},ye={key:4,class:"multiselect-placeholder"},pe={class:"multiselect-options"},he=["onClick"],ge=ue(()=>r("span",{class:"fake-checkbox"},null,-1)),be={key:0,class:"multiselect-no-results"},we={class:"form-error"},Ke={__name:"BaseMultiselect",props:{value:{required:!1},modelValue:{required:!1},mode:{type:String,required:!1,default:"multiple"},id:String,caret:{type:Boolean,default:!0},disabled:Boolean,placeholder:String,options:{type:Array,default:[]},labelKey:{type:String,default:"label"},valueKey:{type:String,default:"value"},allowCustomInput:Boolean,caret:{type:Boolean,default:!0},error:String},emits:["update:modelValue","searchChange"],setup(s,{emit:H}){te(e=>({"053d1af3":W.value}));const l=s,B=H,W=m(250),K=m(!1),p=m(!1),o=m(""),c=m(null),V=m(null);Y(()=>{l.disabled&&c.value.disable()}),I(()=>l.disabled,e=>{e?c.value.disable():c.value.enable()});function j(){K.value=!0}function D(){K.value=!1}const a=m(l.mode==="single"?{}:[]),F=g(()=>l.modelValue!==void 0?l.modelValue:l.value),b=g(()=>l.options.map(e=>typeof e=="object"?e:{[l.labelKey]:e,[l.valueKey]:e})),O=g(()=>o.value?b.value.filter(e=>e[l.labelKey].toLowerCase().includes(o.value.toLowerCase())):b.value);I(F,e=>{$(e)},{deep:!0,immediate:!0}),I(b,()=>{$(F.value)});function $(e){if(l.mode==="single")a.value=k(e)||{},l.allowCustomInput&&Object.keys(a.value).length===0&&(a.value={[l.labelKey]:e,[l.valueKey]:e});else{if(l.allowCustomInput)throw new Error("Custom Input only allowed in single select mode.");if(e&&!Array.isArray(e))throw new Error(`v-model must be an array when using ${l.mode} mode.`);e||(e=[]),a.value=e.filter(t=>!!k(t)).map(t=>k(t))}}function k(e){return v(e)?e:b.value.find(t=>t[l.valueKey].toLowerCase()===e.toLowerCase())}const U=g(()=>{const e=a.value.length;if(e)return e>1?`${e} options selected`:"1 option selected"});function M(){c.value.state.isVisible||c.value.show(),l.allowCustomInput&&h({[l.labelKey]:o.value,[l.valueKey]:o.value}),B("searchChange",o.value)}function z(){o.value=""}const C=g(()=>l.mode==="single"?!v(a.value[l.valueKey])&&a.value[l.valueKey]!=="":!v(a.value)&&a.value.length>0);function G(e){e.disabled||(l.mode==="single"?(h(e),c.value.hide(),V.value.focus()):A(e)?h(a.value.filter(t=>t[l.valueKey]!==e[l.valueKey])):h(a.value.concat(e)))}function h(e){a.value=v(e)?l.mode==="single"?{}:[]:e;const t=v(e)?e:Array.isArray(e)?e.map(u=>u[l.valueKey]):e[l.valueKey];B("update:modelValue",t)}function A(e){return l.mode==="single"?!v(a.value)&&a.value[l.valueKey]===e[l.valueKey]:!v(a.value)&&a.value.map(t=>t[l.valueKey]).indexOf(e[l.valueKey])!==-1}function J(e){h(a.value.filter(t=>t[l.valueKey]!==e[l.valueKey]))}const P={modifiers:[{name:"sameWidth",enabled:!0,fn:({instance:e,state:t})=>{const u=`${t.rects.reference.width}px`;t.styles.popper.width!==u&&(t.styles.popper.width=u,e.update())},phase:"beforeWrite",requires:["computeStyles"]}]};function v(e){return e==null}return(e,t)=>(i(),n("div",ie,[L(q(le),{theme:"light",arrow:!1,interactive:"",trigger:"click",offset:[0,2],"max-width":"1200","popper-options":P,onHidden:z,onClick:t[5]||(t[5]=T(()=>{},["prevent"])),ref_key:"tippyRef",ref:c},{default:N(({state:u})=>[r("div",{class:S(["multiselect-wrapper",{active:K.value||u.isVisible,disabled:s.disabled}]),tabindex:"0",onFocusin:j,onFocusout:D,ref_key:"wrapperRef",ref:V},[s.mode==="tags"?(i(),n("div",ne,[(i(!0),n(w,null,R(a.value,d=>(i(),n("span",{class:"multiselect-tag",onMousedown:t[0]||(t[0]=T(()=>{},["stop"]))},[r("span",oe,f(d[s.labelKey]),1),r("span",{class:"multiselect-tag-icon",onClick:Q=>J(d)},"×",8,de)],32))),256)),_(r("input",{type:"text",id:s.id,class:"multiselect-tags-search",ref:"input","onUpdate:modelValue":t[1]||(t[1]=d=>o.value=d),onInput:M},null,40,re),[[E,o.value,void 0,{trim:!0}]])])):y("",!0),s.mode!=="tags"?_((i(),n("input",{key:1,type:"text",id:s.id,class:"multiselect-search",disabled:s.disabled,"onUpdate:modelValue":t[2]||(t[2]=d=>o.value=d),onFocusin:t[3]||(t[3]=d=>p.value=!0),onFocusout:t[4]||(t[4]=d=>p.value=!1),onInput:M},null,40,ce)),[[E,o.value,void 0,{trim:!0}]]):y("",!0),s.mode==="single"&&C.value&&!o.value&&!p.value?(i(),n("div",ve,[r("span",me,f(a.value[s.labelKey]),1)])):y("",!0),s.mode=="multiple"&&C.value&&!o.value&&!p.value?(i(),n("div",fe,f(U.value),1)):y("",!0),s.placeholder&&!C.value&&!o.value&&!p.value?(i(),n("div",ye,f(s.placeholder),1)):y("",!0),s.caret?(i(),n("span",{key:5,class:S(["multiselect-caret",{active:u.isVisible}])},[L(q(Z),{icon:"mdi:caret-down",inline:"true"})],2)):y("",!0)],34)]),content:N(()=>[r("ul",pe,[(i(!0),n(w,null,R(O.value,(u,d)=>(i(),n("li",{key:u[s.valueKey],class:S(["multiselect-option",{disabled:u.disabled,selected:A(u)}]),onClick:Q=>G(u)},[s.mode==="single"?(i(),n(w,{key:0},[x(f(u[s.labelKey]),1)],64)):(i(),n(w,{key:1},[ge,x(" "+f(u[s.labelKey]),1)],64))],10,he))),128)),O.value.length===0?(i(),n("li",be,[ee(e.$slots,"noresults",{},()=>[x(" No results found")],!0)])):y("",!0)])]),_:3},512),r("div",we,f(s.error),1)]))}},Ce=X(Ke,[["__scopeId","data-v-0a0c88ec"]]);export{Ce as B};