import{T as H}from"./props-CLtNejQT.js";import{B as I}from"./BasicForm-dL_oCSPM.js";import{u as J}from"./useForm-CKmgcynv.js";import{d as Q,r as s,dk as X,ay as Z,a4 as u,aj as v,aw as ee,aC as te,c as S,o as b,w as ae,i as le,h as ne,D as k,j as se,A as oe,l as i,aa as ue,aG as C,ac as re,bY as ce,aA as ie}from"./index-9PRMimni.js";import{B as de}from"./Table-0PViRYCf.js";const me={key:0,class:"leading-[42px] border-b-[2px] border-[#e5e7eb] mb-3 font-medium text-lg"},he=Q({__name:"TableSelect",props:{...H,formValues:{type:Object,default:()=>{}}},emits:["press-enter","clear","change","update:value","update:formValues"],setup(D,{expose:R,emit:T}){const n=s(),d=s([]),o=s(),g=s(),F=s([]),m=s({}),f=s(!1),{getDarkTheme:_}=X(),a=D,r=T;Z(()=>a.value,()=>{n.value=a.value},{immediate:!0,deep:!0});const P=u(()=>({width:a.contentWidth,color:_.value?"#fff":"#000"})),V=u(()=>({width:a.width})),B=u(()=>a.disabled),p=u(()=>v(o.value?.getDataSource()||[])),K=u(()=>a.tableProps),E=u(()=>{let e=v(a.tableProps.columns);return e.unshift({type:"selection",multiple:a.multiple,width:70}),e}),[x,{}]=J({...a.formProps});function A(){const e=p.value,t=a.valueField;e.forEach(l=>{m.value[l[t]]||(m.value[l[t]]=l)})}function L(e){r("update:formValues",e),o.value.reload()}function z(){r("update:formValues",{}),o.value.reload()}function j(){y()}function M(e){const t=[];return e.forEach(l=>{m.value[l]&&t.push(m.value[l])}),t}function N(e){const t=i(e);d.value=t.length?M(t):[];const l=d.value.map($=>$[a.labelField]);n.value=h(l);const c=h(d.value);r("change",c),r("update:value",n.value),a.multiple!==!0&&(f.value=!1)}function U(){r("clear")}function h(e){return a.multiple?e:e.length?e[0]:null}function W(){re(()=>{f.value=!0})}function G(e){const t=e?q():[];n.value=t,F.value=t.map(l=>l[a.valueField])}function q(){return p.value.map(t=>t[a.labelField])}function O(){return v(p.value)}function y(){const e=d.value.map(t=>(ce(n.value)?n.value:[n.value]).includes(t[a.labelField])&&t[a.valueField]);o.value?.setCheckedRowKeys(i(e))}function Y(){return o.value}const w=e=>{if(e.key==="Enter"){const t=g.value?.$el,l=document.querySelector(".selectContent");(t?.contains(e.target)||l?.contains(e.target))&&(e.preventDefault(),e.stopPropagation())}};return ee(()=>{document.addEventListener("keydown",w,!0)}),te(()=>{document.removeEventListener("keydown",w,!0)}),R({getDataSource:O,getTableRef:Y,updateTableSelectedKeys:y}),(e,t)=>{const l=ie;return b(),S(l,{ref_key:"selectRef",ref:g,clearable:"",multiple:a.multiple,style:C(V.value),disabled:B.value,"label-field":a.labelField,"value-field":a.valueField,value:n.value,"onUpdate:value":[t[0]||(t[0]=c=>n.value=c),j],show:f.value,"onUpdate:show":t[1]||(t[1]=c=>f.value=c),"consistent-menu-width":!1,onClear:U},{empty:ae(()=>[le("div",{class:"selectContent",style:C(P.value)},[e.selectTitle?(b(),ne("div",me,oe(e.selectTitle),1)):k("",!0),a.formProps.schemas?(b(),S(i(I),{key:1,onReset:z,onRegister:i(x),onSubmit:L,class:"mb-2"},null,8,["onRegister"])):k("",!0),se(i(de),ue({ref_key:"basicTableRef",ref:o},K.value,{columns:E.value,canResize:!1,showTableSetting:!1,isKeepRowKeys:!0,onCheckedRowChange:N,onSelectAll:G,onFetchSuccess:A,onPageSizeChange:W}),null,16,["columns"])],4)]),_:1},8,["multiple","style","disabled","label-field","value-field","value","show"])}}});export{he as _};
