import{u as L}from"./useAsync.24db85a6.js";import{b as w,e as R,p as _,j as c,b6 as m,b7 as V,aB as x,f as C}from"./index.4d3e3847.js";const j={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 B(a){return typeof a=="function"||Object.prototype.toString.call(a)==="[object Object]"&&!x(a)}const D=w({name:"RemoteSelect",props:j,emits:["listChange","itemChange","itenDetail","update:value","inital"],setup(a,{emit:r,expose:h}){const b=R({get(){return a.value},set(l){r("update:value",l)}}),g=L(),t=_([]),n=_(!1);async function S(l){const{responseLabelProp:e,responseValProp:o,subLabelProp:d,api:f}=a;n.value=!0;const{code:v,data:p,message:i}=await f(l);n.value=!1,g({code:v,message:i,handler:()=>{const y=a.isRoot?p:p[a.prop];t.value=y.map(s=>({...s,label:s[e],value:s[o],subLabel:s[d]})),b.value=t.value[0][o],r("inital",t.value[0][o])}})}async function P(l){if(!l)return;const{responseLabelProp:e,responseValProp:o,requestProp:d,subLabelProp:f,api:v}=a;n.value=!0;const{code:p,data:i,message:y}=await v({[d||e]:l});g({code:p,message:y,handler:()=>{const s=a.isRoot?i:i[a.prop];t.value=s.map(u=>({...u,label:u[e],value:u[o],subLabel:u[f],status:u.status+""=="0"})),r("listChange",C(t))}}),n.value=!1}return h({initalData:S}),()=>{let l;return c(V,{class:"w-full",modelValue:b.value,"onUpdate:modelValue":e=>b.value=e,placeholder:a.placeholder,remoteMethod:P,loading:n.value,disabled:a.disabled,reserveKeyword:!0,filterable:!0,clearable:!0,remote:!0,style:{wdith:a.width?a.width+"px":""},onChange:e=>{r("itemChange",t.value.find(o=>o.value===e))}},B(l=t.value.map(e=>c(m,{label:e.subLabel?e.label+" - "+e.subLabel:e.label,key:e.value,value:e.value,disabled:a.showDisabled?e.status:!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])]})))?l:{default:()=>[l]})}}}),E=D;export{E as R};
