import{_ as B,G as O,o,c as s,a as c,d as _,l as n,b as f,s as y,F as h,q as r,t as v,p as x,y as D,f as q}from"./CmnEfQIC.js";import{u as F,_ as L}from"./AdminButtonElement-BgARiw82.mjs";import{_ as T}from"./WebSearchFilterCount-BAo3tYv2.mjs";import{V as H}from"./vue-select-X0cl5iEg.mjs";import{_ as j}from"./FieldBase_String-DIrYardi.mjs";import"./FieldBase-BNePpS9o.mjs";const z={components:{VueSelect:H},extends:j,props:{options:{type:[Array,Function],required:!0},disableSelectAll:{type:Boolean,default:!1},disableClearSelection:{type:Boolean,default:!0},allowAddNew:{type:Boolean,default:!1},allowMultiple:{type:Boolean,default:!1},status:{type:String,default:"init"},loading:{type:Boolean,default:!1},value:{type:[String,Array,Object,Number],default:void 0},defaultValue:{type:[String,Array,Object,Number],default:void 0}},emits:["changeValue","search","add-new"],async setup(e){const a=typeof e.options=="function"?await e.options():e.options,i=e.value??(e.allowMultiple?[]:void 0),d=e.defaultValue??(e.allowMultiple?[]:void 0);return{dataOptions:a,conditionalValue:i,conditionalDefaultValue:d}},data(){return{localVal:this.conditionalValue||this.conditionalValue===0?this.conditionalValue:this.conditionalDefaultValue}},computed:{currValue(){return this.allowMultiple?Array.isArray(this.conditionalValue)&&this.conditionalValue.length>0?this.conditionalValue:this.conditionalDefaultValue:(this.conditionalValue||this.conditionalValue===0)&&!Array.isArray(this.conditionalValue)?this.conditionalValue:this.conditionalDefaultValue&&!Array.isArray(this.conditionalDefaultValue)?this.conditionalDefaultValue:""},showSelectAll(){return!!(!this.disableSelectAll&&this.allowMultiple)},computedOptions(){return typeof this.options=="function"?this.dataOptions:this.options},adminStyles(){return F()},cssVars(){var u;const e=(u=this.computedOptions)==null?void 0:u.find(t=>t.value===this.localVal),a=e==null?void 0:e.color,i=a??"#9da4b0",d=e!=null&&e.color?`${e==null?void 0:e.color}10`:"white";return{"--selected-color":a,"--selected-border-color":i,"--selected-background-color":d}}},watch:{value:{handler(e){this.localVal=e},deep:!0}},methods:{selectAll(){const e=this.computedOptions.map(a=>a.value);this.localVal=e,this.update(e)},clear(){this.localVal=this.allowMultiple?[]:null,this.update(this.allowMultiple?[]:null)},emitSearch(...e){this.$emit("search",...e)},addNew(e){this.$emit("add-new",this.name,e)},validate(e){return this.required&&(e==null||this.allowMultiple&&e.length===0||!this.allowMultiple&&`${e}`.trim()==="")?{valid:!1,errors:["Field is required"]}:{valid:!0,errors:[]}},update(e){const a=this.validate?this.validate(e):{valid:!0,errors:[]};this.$emit("changeValue",this.name,e,a)}}},E={class:"ebm-multi-select"},U={key:0,class:"spinner"},G={key:4,class:"no-options"},I={class:"option"},W={key:0},J=["innerHTML"],K={key:1,class:D("count")},P={class:"option"},Q={key:0},R=["innerHTML"],X={key:2,class:"links"},Y={key:3,class:"placeholder"};function Z(e,a,i,d,u,t){var V,p,w,S,b,g;const m=q,C=L,M=T,N=O("VueSelect");return o(),s("div",E,[t.computedOptions?n("",!0):(o(),s("div",U,[c("div",null,[_(m,{icon:"ei:spinner-3",width:40,"icon-color":t.adminStyles.darkColor},null,8,["icon-color"])])])),t.computedOptions?(o(),f(N,{key:1,modelValue:u.localVal,"onUpdate:modelValue":[a[0]||(a[0]=l=>u.localVal=l),t.update],placeholder:"Select...",class:"select",options:t.computedOptions,reduce:l=>l.value,label:"label",disabled:e.disabled,multiple:i.allowMultiple,loading:i.loading,clearable:!e.required,style:x(t.cssVars),onSearch:t.emitSearch},{"no-options":y(({search:l})=>[i.status==="loading"?(o(),s(h,{key:0},[r(" Loading results... ")],64)):n("",!0),i.status==="short"?(o(),s(h,{key:1},[r(" Search phrase must be longer ")],64)):n("",!0),!i.allowAddNew&&i.status==="loaded"?(o(),s(h,{key:2},[r(' No results found for "'+v(l)+'". ',1)],64)):n("",!0),i.status==="init"?(o(),s(h,{key:3},[r(" Start typing to search. ")],64)):n("",!0),i.status==="loaded"?(o(),s("div",G,[a[3]||(a[3]=r(" No items found. ")),i.allowAddNew?(o(),f(C,{key:0,icon:"gridicons:add-outline",size:"small",mode:"solid",label:"Create New","icon-color":t.adminStyles.darkColor,onClick:()=>{t.addNew(l)}},null,8,["icon-color","onClick"])):n("",!0)])):n("",!0)]),option:y(l=>{var k,A;return[c("div",I,[l.icon?(o(),s("div",W,[_(m,{icon:l.icon,width:20},null,8,["icon"])])):n("",!0),c("div",{innerHTML:l.label},null,8,J),l.count?(o(),s("div",K,v((A=(k=l.count)==null?void 0:k.toString())==null?void 0:A.replace(/(.)(?=(\d{3})+$)/g,"$1,")),1)):n("",!0)])]}),"selected-option":y(l=>[c("div",P,[l.icon?(o(),s("div",Q,[_(m,{icon:l.icon,width:20},null,8,["icon"])])):n("",!0),c("div",{innerHTML:l.label},null,8,R),l.count?(o(),f(M,{key:1,alternate:!0,count:l.count},null,8,["count"])):n("",!0)])]),_:1},8,["modelValue","options","reduce","disabled","multiple","loading","clearable","style","onSearch","onUpdate:modelValue"])):n("",!0),!e.disabled&&(t.showSelectAll&&((V=t.computedOptions)==null?void 0:V.length)>((p=u.localVal)==null?void 0:p.length)||(w=u.localVal)!=null&&w.length)?(o(),s("div",X,[t.showSelectAll&&((S=t.computedOptions)==null?void 0:S.length)>((b=u.localVal)==null?void 0:b.length)?(o(),s("a",{key:0,onClick:a[1]||(a[1]=(...l)=>t.selectAll&&t.selectAll(...l))},"Select All")):n("",!0),i.allowMultiple&&((g=u.localVal)!=null&&g.length)?(o(),s("a",{key:1,onClick:a[2]||(a[2]=(...l)=>t.clear&&t.clear(...l))},"Clear Selection")):n("",!0)])):n("",!0),t.computedOptions?n("",!0):(o(),s("div",Y))])}const ne=B(z,[["render",Z]]);export{ne as default};