import{s as I}from"./app-BZGObKCm.js";import{r as _,J as C,ak as F,o as u,g as f,b as j,w as H,t as k,a as R,u as g,x as A,j as M,W as v,K as T,aa as L,b9 as E,aE as U}from"./app-SC54XQDl.js";const G={key:0},D={key:0},J={key:1},K={key:2},P=["name","value"],W={key:1},q={key:0},z={key:1},Q={class:"hidden"},X={inheritAttrs:!1},ee=Object.assign(X,{__name:"TSelect",props:{name:String,items:Array,optionLabel:String,optionValue:String,modelValue:null,value:null,scrollHeight:""},emits:["update:modelValue","change"],setup(y,{emit:d}){const n=y,o=_([]);if(n.items!==null&&n.items instanceof Array)for(let e of n.items)o.value.push(e);let s=n.optionLabel;v.isNull(s)&&(s="name");let l=n.optionValue;v.isNull(l)&&(l="value");let p=n.scrollHeight;(typeof p!="string"||p.length==0)&&(p="18rem");const a=_(),c=_();T("$addSelectOption",(e,t)=>{v.isNull(t)||(t=t.toString());for(let i of o.value)if(i[s]===e&&i[l]===t)return;o.value.push({[s]:e,[l]:t})}),T("$removeSelectOption",(e,t)=>{v.isNull(t)||(t=t.toString());const i=[];for(const m of o.value)m[s]===e&&m[l]===t||i.push(m);o.value=i}),T("$updateSelectOption",(e,t,i,m)=>{v.isNull(t)||(t=t.toString()),v.isNull(m)||(m=m.toString());for(const V of o.value)if(V[s]===e&&V[l]===t){V[s]=i,V[l]=m;break}N()});const h=d,r=_("");C(()=>n.modelValue,e=>{r.value=e});let b;const N=()=>{b!=null&&clearTimeout(b),b=setTimeout(()=>{o.value.length>0&&(o.value.find(e=>e[l]==r.value)||(r.value=o.value[0][l],h("update:modelValue",S(r.value))))},100)};C(()=>o.value,()=>{N()});const O=e=>{const t=typeof e;return t==="number"||t==="string"};F(()=>{setTimeout(()=>{if(O(n.modelValue)){r.value=n.modelValue;return}if(O(n.value)){r.value=n.value,h("update:modelValue",S(n.value));return}let e=c.value.modelValue;o.value.length>0&&(typeof e!="string"&&typeof e!="number"||!o.value.find(t=>t[l]==e))&&(h("update:modelValue",S(o.value[0][l])),r.value=o.value[0][l])},15)});const w=e=>{for(const t of o.value)if(typeof t[l]=="string"&&t[l]===e.toString())return t[s];return""},$=()=>{for(const e of o.value)if(typeof e[l]=="string"&&e[l].length==0)return e[s];return""},x=e=>{h("update:modelValue",S(e))},S=e=>typeof n.modelValue=="number"&&e!=null&&e.toString().length>0?parseInt(e):typeof n.modelValue=="string"&&e!=null||e!=null?e.toString():e,B=e=>{h("change",r.value)};return(e,t)=>(u(),f("div",{ref_key:"rootRef",ref:a,class:"inline-block"},[j(g(I),A({ref_key:"selectRef",ref:c,options:o.value},e.$attrs,{optionLabel:g(s),optionValue:g(l),optionGroupLabel:"",optionGroupChildren:"items","onUpdate:modelValue":[x,t[0]||(t[0]=i=>r.value=i)],onChange:B,scrollHeight:g(p),modelValue:r.value}),{value:H(({value:i})=>[typeof i=="string"||typeof i=="number"?(u(),f("span",G,[i.toString().length>0?(u(),f("span",D,k(w(i)),1)):$().length>0?(u(),f("span",J,k($()),1)):(u(),f("span",K," ")),R("input",{type:"hidden",name:y.name,value:i,class:"hidden"},null,8,P)])):(u(),f("span",W," "))]),option:H(({option:i})=>[typeof i[g(s)]=="string"&&i[g(s)].length>0?(u(),f("span",q,k(i[g(s)]),1)):(u(),f("span",z," "))]),_:1},16,["options","optionLabel","optionValue","scrollHeight","modelValue"]),R("div",Q,[M(e.$slots,"default")])],512))}}),te={__name:"TOption",props:["name","value"],setup(y){const d=y,n=_();let o,s,l;const p=()=>{let a=d.name;return(typeof a!="string"||a.length===0)&&(a=n.value.textContent,(typeof a!="string"||a.length===0)&&(a=n.value.innerText)),a};return F(()=>{o=n.value.innerHTML;let a=p();s=a,l=d.value,L("$addSelectOption")(a,d.value)}),E(()=>{let a=p();L("$removeSelectOption")(a,d.value)}),U(()=>{if(o!=n.value.innerHTML){o=n.value.innerHTML;const a=p(),c=d.value;L("$updateSelectOption")(s,l,a,c),s=a,l=c}}),(a,c)=>(u(),f("div",{ref_key:"rootRef",ref:n},[M(a.$slots,"default")],512))}};export{ee as _,te as a};
