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