import{ay as e,aL as t,aK as i,e as s,k as l,aO as a}from"./vendor-element-plus.js?ver=3.1.10";import{W as o,X as d,Z as n,a6 as r,Y as p,a5 as m,J as h,az as c,aa as f,a8 as _,ab as u,a9 as y,a0 as w}from"./vendor.js?ver=3.1.10";import{_ as g}from"./fc-bits-ui.js?ver=3.1.10";const v={class:"w-full"},V=["textContent"],b={class:"fcrm_option_selector d-flex items-center gap-8"},k={key:0,class:"fcrm_field_inline_help"};const $=g({name:"OptionSelector",props:["modelValue","field","placement","effect","popper_class"],emits:["element_ready","renew_options","update:modelValue"],data(){return{options:{},model:this.modelValue&&Array.isArray(this.modelValue)?this.modelValue.map(String):this.modelValue,element_ready:!1,new_item:"",creating:!1,isInternalUpdate:!1}},watch:{model(e){this.isInternalUpdate||this.$emit("update:modelValue",e)},modelValue(e){const t=e&&Array.isArray(e)?e.map(String):e;JSON.stringify(this.model)!==JSON.stringify(t)&&(this.isInternalUpdate=!0,this.model=t,this.$nextTick(()=>{this.isInternalUpdate=!1}))}},methods:{getOptions(){this.app_ready=!1;const e={fields:"editable_statuses,"+this.field.option_key};this.$get("reports/options",e).then(e=>{window.fc_options_cache=e.options,this.options=e.options,this.element_ready=!0,this.$emit("element_ready")}).catch(e=>{this.handleError(e)}).finally(()=>{})},createNewItem(){if(this.creating=!0,!this.new_item.length)return this.$notify.error("Provide name Field is required"),!1;this.$post(this.field.option_key+"/bulk",{items:[{title:this.new_item}]}).then(e=>{this.$notify.success(e.message),this.getOptions(),e.ids&&e.ids[0]&&(this.field.is_multiple?this.model=[...this.model,String(e.ids[0])]:this.model=String(e.ids[0])),this.new_item="","tags"==this.field.option_key?this.$bus.emit("renew_options","tag"):"lists"==this.field.option_key&&this.$bus.emit("renew_options","list")}).catch(e=>{this.handleError(e)}).finally(()=>{this.creating=!1})}},mounted(){this.field.is_multiple&&"object"!=typeof this.modelValue&&(this.model=[]),"tags"==this.field.option_key?(this.options[this.field.option_key]=this.appVars.available_tags,this.element_ready=!0,this.$emit("element_ready")):"lists"==this.field.option_key?(this.options[this.field.option_key]=this.appVars.available_lists,this.element_ready=!0,this.$emit("element_ready")):window.fc_options_cache&&window.fc_options_cache[this.field.option_key]?(this.options=window.fc_options_cache,this.element_ready=!0,this.$emit("element_ready")):this.getOptions()}},[["render",function(g,$,x,O,S,I){const H=t,N=i,U=s,A=l,j=a,z=e;return o(),d("div",v,[n("div",{class:w(["fcrm_options_selector",x.field.creatable?"fcrm_option_creatable":""])},[r((o(),p(N,{disabled:x.field.disabled,size:x.field.size,modelValue:S.model,"onUpdate:modelValue":$[0]||($[0]=e=>S.model=e),class:"fcrm_options","value-key":"id",multiple:x.field.is_multiple,placeholder:x.field.placeholder,clearable:"",filterable:"",effect:x.effect||x.field.effect,"popper-class":x.popper_class||x.field.popper_class||x.field.popperClass,teleported:!1!==x.field.teleported},{default:m(()=>[S.element_ready?(o(!0),d(h,{key:0},c(S.options[x.field.option_key],e=>(o(),p(H,{key:e.id,value:Number.isInteger(e.id)?String(e.id):e.id,label:e.title},{default:m(()=>[n("span",{textContent:f(e.title)},null,8,V)],void 0,!0),_:2},1032,["value","label"]))),128)):_("",!0)],void 0),_:1},8,["disabled","size","modelValue","multiple","placeholder","effect","popper-class","teleported"])),[[z,!S.element_ready]]),x.field.creatable&&!x.field.disabled?(o(),p(j,{key:0,placement:x.placement?x.placement:"left",width:250,trigger:"click"},{reference:m(()=>[u(A,{class:"fcrm_with_select",type:"info"},{default:m(()=>[...$[3]||($[3]=[n("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[n("path",{d:"M9.25 9.25V4.75H10.75V9.25H15.25V10.75H10.75V15.25H9.25V10.75H4.75V9.25H9.25Z",fill:"var(--fc-secondary-text)"})],-1)])],void 0,!0),_:1})]),default:m(()=>[n("div",b,[u(U,{placeholder:g.$t("Provide Name"),modelValue:S.new_item,"onUpdate:modelValue":$[1]||($[1]=e=>S.new_item=e)},null,8,["placeholder","modelValue"]),u(A,{onClick:$[2]||($[2]=e=>I.createNewItem()),type:"primary"},{default:m(()=>[y(f(g.$t("Add")),1)],void 0,!0),_:1})])],void 0),_:1},8,["placement"])):_("",!0)],2),x.field.inline_help?(o(),d("span",k,f(x.field.inline_help),1)):_("",!0)])}]]);export{$ as O};
