/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{computed as e,ref as t,reactive as l,onMounted as n,onBeforeUnmount as o,watch as c,openBlock as a,createElementBlock as i,normalizeStyle as r,createElementVNode as s,Fragment as u,renderList as d,createCommentVNode as g,withModifiers as m,normalizeClass as p,unref as v,createBlock as f,toDisplayString as h,withCtx as y,renderSlot as b,createVNode as k,createTextVNode as x}from"vue";import{FlexRender as w}from"../../../node_modules/@tanstack/vue-table/build/lib/index.js";import C from"./ColumnFilter.vue.js";import S from"./CellEditor.vue.js";import{useLocale as D}from"../../../hooks/useLocale.js";import{GscButton as R}from"../../../Button/index.js";import './DataTable.css';/* empty css              */import z from"../../../_virtual/_plugin-vue_export-helper.js";const $={class:"w-full"},I={class:"gsc-table"},M={class:"gsc-thead sticky top-0 z-10"},A=["checked",".indeterminate"],P=["onDrop"],_={class:"flex items-center gap-2 min-w-0"},V=["onClick"],j=["title","onDragstart"],H={class:"truncate"},O={key:0,class:"text-[rgba(0,0,0,0.45)] text-xs"},T=["onMousedown"],U=["checked","onChange"],B=["onDblclick"],L={key:1,class:"flex items-start gap-2"},W={class:"min-w-0 flex-1"},E={key:1,class:"break-words"},F={key:0},N=["colspan"],q={key:1,class:"w-full"},G={class:"gsc-table"},K={class:"gsc-thead sticky top-0 z-10"},J=["checked",".indeterminate"],Q=["onDrop"],X={class:"flex items-center gap-2 min-w-0"},Y=["onClick"],Z=["title","onDragstart"],ee={class:"truncate"},te={key:0,class:"text-[rgba(0,0,0,0.45)] text-xs"},le=["onMousedown"],ne={class:"gsc-table"},oe=["checked","onChange"],ce=["onDblclick"],ae={key:1,class:"break-words"},ie={key:0},re=["colspan"],se=/* @__PURE__ */z({__name:"DataTable",props:{table:{type:Object,required:!0},mode:{type:String,default:"server"},loading:{type:Boolean,default:!1},virtual:{type:Boolean,default:!1},height:{type:[Number,String],default:400},rowHeight:{type:Number,default:40},enableRowSelection:{type:Boolean,default:!1}},emits:["selection-change","cell-change","server-filter-change"],setup(z,{emit:se}){const ue=z,de=se,{t:ge}=D(),me=e(()=>ue.table),pe=e(()=>{try{return me.value.getHeaderGroups?.()||[]}catch{return[]}}),ve=e(()=>{try{return me.value.getRowModel?.().rows||[]}catch{return[]}}),fe=e(()=>(me.value.getVisibleLeafColumns?.()||[]).length+(ue.enableRowSelection?1:0));function he(e){const t=e.getIsSorted?.();return"asc"===t?"↑":"desc"===t?"↓":""}function ye(e,t){const l=t.column;if(!l.getCanSort?.())return;const n=!!e?.shiftKey;l.toggleSorting?.(void 0,n)}const be=t(null);function ke(e,t){be.value=t?.id??null;try{e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",String(t?.id??""))}catch{}}function xe(e){const t=e?.getIsPinned?.();return"left"===t?"left":"right"===t?"right":"center"}function we(e,t,l){const n=e.indexOf(t),o=e.indexOf(l);if(-1===n||-1===o)return e;if(n===o)return e;const c=e.slice();return c.splice(n,1),c.splice(o,0,t),c}function Ce(e,t){const l=t?.id;let n=be.value;try{const t=e.dataTransfer.getData("text/plain");t&&(n=t)}catch{}if(!n||!l||n===l)return void(be.value=null);const o=(me.value.getAllLeafColumns?.()||[]).filter(Boolean),c=o.find(e=>e.id===n),a=o.find(e=>e.id===l);if(!c||!a)return void(be.value=null);const i=xe(c);if(i!==xe(a))return void(be.value=null);const r=o.filter(e=>"left"===xe(e)).map(e=>e.id),s=o.filter(e=>"center"===xe(e)).map(e=>e.id),u=o.filter(e=>"right"===xe(e)).map(e=>e.id);let d=r,g=s,m=u;"left"===i?d=we(r,n,l):"right"===i?m=we(u,n,l):g=we(s,n,l),me.value.setColumnOrder?.([...d,...g,...m]),be.value=null}function Se(e){const t=e.getIsPinned?.();if("left"===t){return{position:"sticky",left:`${(e.getStart?.("left")??0)+(ue.enableRowSelection?44:0)}px`,zIndex:2}}if("right"===t){return{position:"sticky",right:`${e.getAfter?.("right")??0}px`,zIndex:2}}return{}}const De=e(()=>ue.enableRowSelection?{width:"44px",minWidth:"44px",position:"sticky",left:"0px",zIndex:4}:{}),Re=e(()=>ue.enableRowSelection?{width:"44px",minWidth:"44px",position:"sticky",left:"0px",zIndex:3}:{}),ze=e(()=>{if(ue.virtual)return{};const e=ue.height;return null==e||""===e?{}:"number"==typeof e?{height:`${e}px`,overflow:"auto"}:"auto"===e||"100%"===e?{height:"100%",overflow:"auto"}:{height:String(e),overflow:"auto"}});function $e(e){const t=e.column,l=e.getSize?.();return{width:l?`${l}px`:void 0,minWidth:t.columnDef?.minSize?`${t.columnDef.minSize}px`:void 0,position:"relative",...Se(t)}}function Ie(e){const t=e.column,l=t.getSize?.();return{width:l?`${l}px`:void 0,minWidth:t.columnDef?.minSize?`${t.columnDef.minSize}px`:void 0,...Se(t)}}const Me=t(null),Ae=l({});function Pe(e){const t=e?.columnDef?.meta?.col;return!!(t?.filterable||t?.filterType||t?.filterOptions)}function _e(e){const t=e?.columnDef?.meta?.col;return t?.filterType||"text"}function Ve(e){const t=e?.columnDef?.meta?.col;return t?.filterOptions||[]}function je(e){Me.value=Me.value===e?null:e}function He(e,t){Ae[e]=t}function Oe(e){if("server"===ue.mode)return de("server-filter-change",{key:e,value:Ae[e]}),void(Me.value=null);const t=me.value.getColumn?.(e);t?.setFilterValue?.(Ae[e]),Me.value=null}function Te(e){if(Ae[e]="","server"===ue.mode)return de("server-filter-change",{key:e,value:""}),void(Me.value=null);const t=me.value.getColumn?.(e);t?.setFilterValue?.(""),Me.value=null}function Ue(){Me.value=null}n(()=>{document.addEventListener("click",Ue)}),o(()=>{document.removeEventListener("click",Ue)}),c(()=>me.value.getState?.().rowSelection,()=>{if(ue.enableRowSelection)try{const e=me.value.getSelectedRowModel?.().rows||[];de("selection-change",e.map(e=>e.original))}catch{}},{deep:!0});const Be=l({});function Le(e,t){return`${e.id}::${t.id}`}function We(e){const t=e?.columnDef?.meta?.col;return!!t?.editor}function Ee(e){const t=e?.columnDef?.meta?.col;return t?.editor?"input"===t.editor?"text":t.editor:"text"}function Fe(e){const t=e?.columnDef?.meta?.col;return t?.options||[]}function Ne(e,t){if(!We(t))return;const l=Le(e,t);Be[l]=e.original?.[t.id]}function qe(e,t){const l=Le(e,t);return Object.prototype.hasOwnProperty.call(Be,l)}function Ge(e,t){const l=Le(e,t);return Be[l]}function Ke(e,t,l){const n=Le(e,t);Be[n]=l}function Je(e,t){const l=Le(e,t);delete Be[l]}function Qe(e,t,l){const n=Le(e,t);try{e.original[t.id]=l}catch{}de("cell-change",{row:e.original,rowId:e.id,column:t.id,value:l}),delete Be[n]}const Xe=t(0);function Ye(e){Xe.value=e.target.scrollTop||0}const Ze=e(()=>Math.ceil(ue.height/ue.rowHeight)+6),et=e(()=>Math.max(0,Math.floor((Xe.value||0)/ue.rowHeight))),tt=e(()=>et.value+Ze.value),lt=e(()=>ve.value.slice(et.value,tt.value)),nt=e(()=>et.value*ue.rowHeight),ot=e(()=>Math.max(0,(ve.value.length-tt.value)*ue.rowHeight));return(e,t)=>(a(),i("div",$,[z.virtual?(a(),i("div",q,[s("table",G,[s("thead",K,[(a(!0),i(u,null,d(pe.value,e=>(a(),i("tr",{key:e.id},[z.enableRowSelection?(a(),i("th",{key:0,class:"gsc-th text-center",style:r(De.value)},[s("input",{type:"checkbox",class:"gsc-checkbox",checked:me.value.getIsAllPageRowsSelected?.(),".indeterminate":me.value.getIsSomePageRowsSelected?.(),onChange:t[2]||(t[2]=e=>me.value.toggleAllPageRowsSelected?.(!!e.target.checked))},null,40,J)],4)):g("",!0),(a(!0),i(u,null,d(e.headers,e=>(a(),i("th",{key:e.id,class:"gsc-th",style:r($e(e)),onDragover:t[3]||(t[3]=m(()=>{},["prevent"])),onDrop:t=>Ce(t,e.column)},[s("div",X,[s("div",{class:p(["flex items-center gap-1 min-w-0",e.column.getCanSort?.()?"cursor-pointer":""]),onClick:t=>ye(t,e)},[s("span",{class:"text-[rgba(0,0,0,0.25)] hover:text-[rgba(0,0,0,0.45)] cursor-grab select-none",title:v(ge)("gsc.grid.table.dragReorder"),draggable:"true",onDragstart:t=>ke(t,e.column)}," ⋮⋮ ",40,Z),s("span",ee,[e.isPlaceholder?g("",!0):(a(),f(v(w),{key:0,render:e.column.columnDef.header,props:e.getContext()},null,8,["render","props"]))]),e.column.getCanSort?.()?(a(),i("span",te,h(he(e.column)),1)):g("",!0)],10,Y),Pe(e.column)?(a(),f(v(R),{key:0,type:"button",variant:"text",size:"icon",class:"ml-auto gsc-btn-icon-sm",title:v(ge)("gsc.grid.table.filter"),"aria-label":v(ge)("gsc.grid.table.filter"),onClick:m(t=>je(e.column.id),["stop"])},{default:y(()=>[...t[6]||(t[6]=[s("i",{class:"i-material-symbols:filter-alt-outline","aria-hidden":"true"},null,-1)])]),_:1},8,["title","aria-label","onClick"])):g("",!0)]),Me.value===e.column.id?(a(),f(C,{key:0,value:Ae[e.column.id],type:_e(e.column),options:Ve(e.column),"onUpdate:value":t=>He(e.column.id,t),onApply:t=>Oe(e.column.id),onClear:t=>Te(e.column.id)},null,8,["value","type","options","onUpdate:value","onApply","onClear"])):g("",!0),e.column.getCanResize?.()?(a(),i("div",{key:1,class:"absolute right-0 top-0 h-full w-2 cursor-col-resize",onMousedown:m(t=>e.getResizeHandler?.()(t),["prevent"])},null,40,le)):g("",!0)],44,Q))),128))]))),128))])]),s("div",{class:"overflow-auto",style:r({height:`${z.height}px`}),onScroll:Ye},[s("div",{style:r({height:`${nt.value}px`})},null,4),s("table",ne,[s("tbody",null,[(a(!0),i(u,null,d(lt.value,e=>(a(),i("tr",{key:e.id,class:"gsc-tr",style:r({height:`${z.rowHeight}px`})},[z.enableRowSelection?(a(),i("td",{key:0,class:"gsc-td text-center",style:r(Re.value)},[s("input",{type:"checkbox",class:"gsc-checkbox",checked:e.getIsSelected?.(),onChange:t=>e.toggleSelected?.(!!t.target.checked)},null,40,oe)],4)):g("",!0),(a(!0),i(u,null,d(e.getVisibleCells(),t=>(a(),i("td",{key:t.id,class:"gsc-td align-top",style:r(Ie(t)),onDblclick:l=>Ne(e,t.column)},[qe(e,t.column)?(a(),f(S,{key:0,"model-value":Ge(e,t.column),type:Ee(t.column),options:Fe(t.column),onUpdateModelValue:l=>Ke(e,t.column,l),onCommit:l=>Qe(e,t.column,l),onCancel:l=>Je(e,t.column)},null,8,["model-value","type","options","onUpdateModelValue","onCommit","onCancel"])):(a(),i("span",ae,[k(v(w),{render:t.column.columnDef.cell,props:t.getContext()},null,8,["render","props"])]))],44,ce))),128))],4))),128)),0===lt.value.length?(a(),i("tr",ie,[s("td",{colspan:fe.value,class:"px-3 py-10 text-center text-sm text-[rgba(0,0,0,0.45)]"},h(z.loading?v(ge)("gsc.grid.table.loading"):v(ge)("gsc.grid.table.empty")),9,re)])):g("",!0)])]),s("div",{style:r({height:`${ot.value}px`})},null,4)],36)])):(a(),i("div",{key:0,class:"overflow-auto",style:r(ze.value)},[s("table",I,[s("thead",M,[(a(!0),i(u,null,d(pe.value,e=>(a(),i("tr",{key:e.id},[z.enableRowSelection?(a(),i("th",{key:0,class:"gsc-th text-center",style:r(De.value)},[s("input",{type:"checkbox",class:"gsc-checkbox",checked:me.value.getIsAllPageRowsSelected?.(),".indeterminate":me.value.getIsSomePageRowsSelected?.(),onChange:t[0]||(t[0]=e=>me.value.toggleAllPageRowsSelected?.(!!e.target.checked))},null,40,A)],4)):g("",!0),(a(!0),i(u,null,d(e.headers,e=>(a(),i("th",{key:e.id,class:"gsc-th",style:r($e(e)),onDragover:t[1]||(t[1]=m(()=>{},["prevent"])),onDrop:t=>Ce(t,e.column)},[s("div",_,[s("div",{class:p(["flex items-center gap-1 min-w-0",e.column.getCanSort?.()?"cursor-pointer":""]),onClick:t=>ye(t,e)},[s("span",{class:"text-[rgba(0,0,0,0.25)] hover:text-[rgba(0,0,0,0.45)] cursor-grab select-none",title:v(ge)("gsc.grid.table.dragReorder"),draggable:"true",onDragstart:t=>ke(t,e.column)}," ⋮⋮ ",40,j),s("span",H,[e.isPlaceholder?g("",!0):(a(),f(v(w),{key:0,render:e.column.columnDef.header,props:e.getContext()},null,8,["render","props"]))]),e.column.getCanSort?.()?(a(),i("span",O,h(he(e.column)),1)):g("",!0)],10,V),Pe(e.column)?(a(),f(v(R),{key:0,type:"button",variant:"text",size:"icon",class:"ml-auto gsc-btn-icon-sm",title:v(ge)("gsc.grid.table.filter"),"aria-label":v(ge)("gsc.grid.table.filter"),onClick:m(t=>je(e.column.id),["stop"])},{default:y(()=>[...t[4]||(t[4]=[s("i",{class:"i-material-symbols:filter-alt-outline","aria-hidden":"true"},null,-1)])]),_:1},8,["title","aria-label","onClick"])):g("",!0)]),Me.value===e.column.id?(a(),f(C,{key:0,value:Ae[e.column.id],type:_e(e.column),options:Ve(e.column),"onUpdate:value":t=>He(e.column.id,t),onApply:t=>Oe(e.column.id),onClear:t=>Te(e.column.id)},null,8,["value","type","options","onUpdate:value","onApply","onClear"])):g("",!0),e.column.getCanResize?.()?(a(),i("div",{key:1,class:"absolute right-0 top-0 h-full w-2 cursor-col-resize",onMousedown:m(t=>e.getResizeHandler?.()(t),["prevent"])},null,40,T)):g("",!0)],44,P))),128))]))),128))]),s("tbody",null,[(a(!0),i(u,null,d(ve.value,l=>(a(),i("tr",{key:l.id,class:"gsc-tr"},[z.enableRowSelection?(a(),i("td",{key:0,class:"gsc-td text-center",style:r(Re.value)},[s("input",{type:"checkbox",class:"gsc-checkbox",checked:l.getIsSelected?.(),onChange:e=>l.toggleSelected?.(!!e.target.checked)},null,40,U)],4)):g("",!0),(a(!0),i(u,null,d(l.getVisibleCells(),n=>(a(),i("td",{key:n.id,class:"gsc-td align-top",style:r(Ie(n)),onDblclick:e=>Ne(l,n.column)},[e.$slots[`cell-${n.column.id}`]?b(e.$slots,`cell-${n.column.id}`,{key:0,value:n.getValue(),row:l.original},void 0,!0):(a(),i("div",L,[s("div",W,[qe(l,n.column)?(a(),f(S,{key:0,"model-value":Ge(l,n.column),type:Ee(n.column),options:Fe(n.column),onUpdateModelValue:e=>Ke(l,n.column,e),onCommit:e=>Qe(l,n.column,e),onCancel:e=>Je(l,n.column)},null,8,["model-value","type","options","onUpdateModelValue","onCommit","onCancel"])):(a(),i("span",E,[k(v(w),{render:n.column.columnDef.cell,props:n.getContext()},null,8,["render","props"])]))]),We(n.column)&&!qe(l,n.column)?(a(),f(v(R),{key:0,variant:"default",class:"shrink-0 mt-0.5 px-2 h-6 text-xs",onClick:m(e=>Ne(l,n.column),["stop"])},{default:y(()=>[...t[5]||(t[5]=[x(" ✎ ",-1)])]),_:1},8,["onClick"])):g("",!0)]))],44,B))),128))]))),128)),0===ve.value.length?(a(),i("tr",F,[s("td",{colspan:fe.value,class:"px-3 py-10 text-center text-sm text-[rgba(0,0,0,0.45)]"},h(z.loading?v(ge)("gsc.grid.table.loading"):v(ge)("gsc.grid.table.empty")),9,N)])):g("",!0)])])],4))]))}},[["__scopeId","data-v-41fc8372"]]);export{se as default};