import{ay as e,aL as i,aK as t}from"./vendor-element-plus.js?ver=3.1.8";import{a6 as l,W as o,Y as a,a5 as s,X as d,J as n,az as r}from"./vendor.js?ver=3.1.8";import{_ as h}from"./fc-bits-ui.js?ver=3.1.8";const m=h({name:"AjaxSelector",props:["field","modelValue"],emits:["change","update:modelValue"],data(){return{model:this.modelValue,loading:!1,options:[]}},watch:{model(e){this.$emit("update:modelValue",e),this.$emit("change",e)}},methods:{fetchOptions(e){let i=this.field.option_key;this.field.extended_key&&(i+="_"+this.field.extended_key);let t="";if(this.field.cacheable){if(t+="_fcrm_ajax_cache_"+i,window[t])return void(this.options=window[t])}else if(this.field.experimental_cache&&(t+="_fcrm_ajax_cache_"+i+"_"+e+" "+JSON.stringify(this.model),this.field.sub_option_key&&(t+="_"+JSON.stringify(this.field.sub_option_key)),window[t]))return void(this.options=window[t]);if(this.doing_ajax)return!1;this.loading=!0;const l={search:e,values:this.model,option_key:i};this.field.sub_option_key&&(l.sub_option_key=this.field.sub_option_key),this.$get("reports/ajax-options",l).then(e=>{this.options=e.options,t&&e.options&&(window[t]=e.options)}).catch(e=>{this.handleError(e)}).finally(()=>{this.loading=!1})}},mounted(){this.fetchOptions("")}},[["render",function(h,m,p,c,f,u){const _=i,b=t,y=e;return l((o(),a(b,{modelValue:f.model,"onUpdate:modelValue":m[0]||(m[0]=e=>f.model=e),multiple:p.field.is_multiple,filterable:"",remote:!p.field.cacheable,clearable:p.field.clearable,disabled:p.field.disabled,"reserve-keyword":"","allow-create":p.field.creatable,size:p.field.size,placeholder:p.field.placeholder||h.$t("Please enter a keyword"),"remote-method":u.fetchOptions},{default:s(()=>[(o(!0),d(n,null,r(f.options,e=>(o(),a(_,{key:e.id,label:e.title,value:e.id},null,8,["label","value"]))),128))],void 0),_:1},8,["modelValue","multiple","remote","clearable","disabled","allow-create","size","placeholder","remote-method"])),[[y,f.loading]])}]]);export{m as A};
