import{ay as e,aL as i,aK as t}from"./vendor-element-plus.js?ver=3.1.0";import{K as l,a as o,o as a,w as s,c as d,Q as n,as as r}from"./vendor.js?ver=3.1.0";import{_ as h}from"./fc-bits-ui.js?ver=3.1.0";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,c,p,f,u){const _=i,b=t,w=e;return l((a(),o(b,{modelValue:f.model,"onUpdate:modelValue":m[0]||(m[0]=e=>f.model=e),multiple:c.field.is_multiple,filterable:"",remote:!c.field.cacheable,clearable:c.field.clearable,disabled:c.field.disabled,"reserve-keyword":"","allow-create":c.field.creatable,size:c.field.size,placeholder:c.field.placeholder||h.$t("Please enter a keyword"),"remote-method":u.fetchOptions},{default:s(()=>[(a(!0),d(n,null,r(f.options,e=>(a(),o(_,{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"])),[[w,f.loading]])}]]);export{m as A};
