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.0";import{c as o,o as d,b as n,L as r,K as p,a as m,w as h,Q as c,as as f,P as _,d as u,O as y,n as w}from"./vendor.js?ver=3.1.0";import{_ as g}from"./fc-bits-ui.js?ver=3.1.0";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,$,O,x,S,I){const H=t,N=i,U=s,A=l,j=a,C=e;return d(),o("div",v,[n("div",{class:w(["fcrm_options_selector",O.field.creatable?"fcrm_option_creatable":""])},[p((d(),m(N,{disabled:O.field.disabled,size:O.field.size,modelValue:S.model,"onUpdate:modelValue":$[0]||($[0]=e=>S.model=e),class:"fcrm_options","value-key":"id",multiple:O.field.is_multiple,placeholder:O.field.placeholder,clearable:"",filterable:"",effect:O.effect||O.field.effect,"popper-class":O.popper_class||O.field.popper_class||O.field.popperClass,teleported:!1!==O.field.teleported},{default:h(()=>[S.element_ready?(d(!0),o(c,{key:0},f(S.options[O.field.option_key],e=>(d(),m(H,{key:e.id,value:Number.isInteger(e.id)?String(e.id):e.id,label:e.title},{default:h(()=>[n("span",{textContent:_(e.title)},null,8,V)],void 0,!0),_:2},1032,["value","label"]))),128)):r("",!0)],void 0),_:1},8,["disabled","size","modelValue","multiple","placeholder","effect","popper-class","teleported"])),[[C,!S.element_ready]]),O.field.creatable&&!O.field.disabled?(d(),m(j,{key:0,placement:O.placement?O.placement:"left",width:250,trigger:"click"},{reference:h(()=>[u(A,{class:"fcrm_with_select",type:"info"},{default:h(()=>[...$[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:h(()=>[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:h(()=>[y(_(g.$t("Add")),1)],void 0,!0),_:1})])],void 0),_:1},8,["placement"])):r("",!0)],2),O.field.inline_help?(d(),o("span",k,_(O.field.inline_help),1)):r("",!0)])}]]);export{$ as O};
