import{u as w}from"./useAsync.df7387ce.js";import{a as R,I as V,r as S,o as C,f as c,ax as x,ay as D,az as _,u as j}from"./index.4d061c66.js";const q={api:{type:Function,required:!0},value:{type:String},subLabelProp:{type:String},requestProp:{type:String},responseLabelProp:{type:String},responseValProp:{type:String},placeholder:{type:String},isRoot:{type:Boolean},width:{type:String},disabled:{type:Boolean,default:!1},showDisabled:{type:Boolean,default:!1},prop:{type:String,default:()=>"list"}};function z(a){return typeof a=="function"||Object.prototype.toString.call(a)==="[object Object]"&&!_(a)}const B=R({name:"RemoteSelect",props:q,emits:["listChange","itemChange","itenDetail","update:value","inital"],setup(a,{emit:d,expose:P}){const i=V({get(){return a.value},set(o){d("update:value",o)}}),g=w(),s=S([]),n=S(!1);async function L(o){const{responseLabelProp:e,responseValProp:t,subLabelProp:u,api:p}=a;n.value=!0;const b={page:1,size:100,...o},{code:f,data:r,message:v}=await p(b);n.value=!1,g({code:f,message:v,handler:()=>{const y=a.isRoot?r:r[a.prop];s.value=y.map(l=>({...l,status:l.status+"",label:l[e]?l[e]+"":"",value:l[t]?l[t]+"":"",subLabel:l[u]?l[u]+"":""})),a.isRoot||(i.value=s.value[0][t]?s.value[0][t]+"":"",d("inital",s.value[0][t]?s.value[0][t]+"":""))}})}async function h(o){if(!o)return;const{responseLabelProp:e,responseValProp:t,requestProp:u,subLabelProp:p,api:b}=a;n.value=!0;const{code:f,data:r,message:v}=await b({[u||e]:o});g({code:f,message:v,handler:()=>{const y=a.isRoot?r:r[a.prop];s.value=y.map(l=>({...l,label:l[e]?l[e]+"":"",value:l[t]?l[t]+"":"",subLabel:l[p]?l[p]+"":"",status:l.status+""})),d("listChange",j(s))}}),n.value=!1}return C(()=>h("")),P({initalData:L}),()=>{let o;return c(D,{class:"w-full",modelValue:i.value,"onUpdate:modelValue":e=>i.value=e,placeholder:a.placeholder,remoteMethod:h,loading:n.value,disabled:a.disabled,reserveKeyword:!0,filterable:!0,clearable:!0,remote:!0,style:{wdith:a.width?a.width+"px":""},onChange:e=>{d("itemChange",s.value.find(t=>t.value===e))}},z(o=s.value.map(e=>c(x,{label:e.subLabel?e.label+" - "+e.subLabel:e.label,key:e.value,value:e.value,disabled:a.showDisabled?e.status+""=="0":!1},{default:()=>[c("span",{style:"float: left"},[e.label]),c("span",{style:"float: right;color: var(--el-text-color-secondary);font-size: 13px;"},[e.subLabel])]})))?o:{default:()=>[o]})}}}),E=B;export{E as R};