/*!
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
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("../../../node_modules/@tanstack/vue-table/build/lib/index.js"),a=require("../../../node_modules/@tanstack/table-core/build/lib/index.js");function l(e=[]){return(e||[]).map(e=>({key:e.key,title:e.title??e.label??e.key,width:e.width,minWidth:e.minWidth,fixed:e.fixed,sortable:!!e.sortable,filterable:!!e.filterable,filterType:e.filterType,filterOptions:e.filterOptions,formatter:e.formatter,editor:e.editor,options:e.options}))}exports.useGridTable=function(n={}){const{data:i=[],request:o,mode:u="server",pageSize:r=10,initialQuery:d={},columns:g=[],rowKey:c="id",enableRowSelection:s=!1}=n,v=e.ref(g||[]),f=e.ref(Array.isArray(i)?(i||[]).slice():(i?.value||[]).slice()),p=e.ref({...d||{}}),m=e.ref(0),y=e.ref(!1),b=e.ref({pageIndex:0,pageSize:r}),h=e.ref([]),w=e.ref({}),S=e.ref({left:[],right:[]}),x=e.ref({}),R=function(t){return e.computed(()=>l(t.value).map(e=>({id:e.key,accessorKey:e.key,header:e.title,size:e.width,minSize:e.minWidth??40,enableSorting:e.sortable,enableResizing:!0,enableHiding:!0,enablePinning:!0,meta:{col:e},cell:t=>{const a=t.getValue();if("function"==typeof e.formatter)try{return e.formatter(a,{row:t.row.original,index:t.row.index})}catch{return String(a??"")}return String(a??"")}})))}(v),C=e.computed(()=>"server"===u&&"function"==typeof o);let M=null,z=!0;function P(){z||(M&&clearTimeout(M),M=setTimeout(()=>{O()},100))}const k=t.useVueTable({get data(){return[...f.value]},get columns(){return R.value},getRowId:(e,t)=>{const a=e&&e[c];return String(0===a||a?a:t)},state:{get sorting(){return h.value},get pagination(){return b.value},get columnVisibility(){return w.value},get columnPinning(){return S.value},get rowSelection(){return x.value}},onSortingChange:e=>{h.value=a.functionalUpdate(e,h.value),C.value&&(b.value={...b.value,pageIndex:0})},onPaginationChange:e=>{b.value=a.functionalUpdate(e,b.value)},onColumnVisibilityChange:e=>{w.value=a.functionalUpdate(e,w.value)},onColumnPinningChange:e=>{S.value=a.functionalUpdate(e,S.value)},enableRowSelection:!!s,onRowSelectionChange:e=>{x.value=a.functionalUpdate(e,x.value)},manualPagination:C.value,manualSorting:C.value,manualFiltering:C.value,pageCount:e.computed(()=>{const e=b.value.pageSize||1;return Math.max(1,Math.ceil((m.value||0)/e))}),enableColumnResizing:!0,columnResizeMode:"onChange",getCoreRowModel:a.getCoreRowModel(),getSortedRowModel:a.getSortedRowModel(),getFilteredRowModel:a.getFilteredRowModel(),getPaginationRowModel:a.getPaginationRowModel()}),I=e.computed({get:()=>(b.value.pageIndex||0)+1,set:e=>{const t=Math.max(1,Number(e||1));b.value={...b.value,pageIndex:t-1}}}),T=e.computed({get:()=>b.value.pageSize,set:e=>{const t=Math.max(1,Number(e||r));b.value={pageIndex:0,pageSize:t}}}),q=e.computed(()=>{const e=h.value&&h.value[0];return{id:e?.id??null,desc:!!e?.desc}}),j=e.computed(()=>{const e=k.getRowModel();return(e?.rows||[]).map(e=>e.original)});async function O(){if(C.value){y.value=!0;try{const e=await o({page:I.value,pageSize:T.value,query:p.value,sort:q.value,sorts:h.value});f.value=(e?.records||[]).slice(),m.value=Number(e?.total??f.value.length)}finally{y.value=!1}}else m.value=f.value.length}function U(e=[]){f.value=(e||[]).slice(),C.value||(m.value=f.value.length)}return i&&"object"==typeof i&&Object.prototype.hasOwnProperty.call(i,"value")&&e.watch(()=>i.value,e=>{U(e||[])},{deep:!0}),e.watch(()=>[b.value.pageIndex,b.value.pageSize,q.value.id,q.value.desc],()=>{C.value&&P()}),e.watch(()=>p.value,()=>{C.value&&P()},{deep:!0}),C.value?(O(),setTimeout(()=>{z=!1},100)):(m.value=f.value.length,z=!1),{table:k,loading:y,query:p,page:I,pageSize:T,total:m,rows:j,sort:function(e){if(!e)return;const t=k.getColumn(e);if(t&&"function"==typeof t.toggleSorting)return void t.toggleSorting(void 0,!1);const a=h.value?.[0];h.value=a?.id===e?[{id:e,desc:!a.desc}]:[{id:e,desc:!1}]},sortState:q,sorting:h,columnVisibility:w,columnPinning:S,rowSelection:x,load:O,setQuery:function(e={}){p.value={...e||{}},C.value&&(b.value={...b.value,pageIndex:0})},setData:U,setColumns:function(e=[]){v.value=(e||[]).slice();try{const t=l(e||[]),a=t.filter(e=>"left"===e.fixed).map(e=>e.key),n=t.filter(e=>"right"===e.fixed).map(e=>e.key);k.setColumnPinning?.({left:a,right:n})}catch{}},mode:u}};