import{ProTable as e}from"@ant-design/pro-components";import t from"dayjs";import{useState as o,useEffect as n,useMemo as r}from"react";import{throttle as s}from"throttle-debounce";import{useAntdResizableHeader as a}from"use-antd-resizable-header";import{getDataType as i,getIndexColumn as l}from"../../utils/index.js";import"use-antd-resizable-header/dist/style.css";import"./index.less";import{jsx as c}from"react/jsx-runtime";const d="tableLocalStorageLastCleanup";function m(e){const t=process.env?.app?.basename,o=decodeURIComponent(window.location.pathname),n="Undefined"===i(e)?"":`#{${e}}`;return{size:`${t}#${o}${n}#size`,resizable:`${t}#${o}${n}#resizable`,columnState:`${t}#${o}${n}#columnState`}}function u(i){const{columns:u=[],showIndexColumn:p=!0,ellipsis:b=!0,align:g="center",indexColumnFixed:f="left",rowKey:h="id",storeIndex:y,disabledResizer:S=!1,height:w,...z}=i,$=process.env.app.antd["ant-prefix"],x=`.${$||"ant"}-table`,v=`${x}-wrapper`,C=`${x}-body`,[I,R]=o((_=y,window.localStorage.getItem(m(_).size)||"default"));var _;const[E,K]=o(0),N=m(y),T=!S,{components:W,resizableColumns:j,tableWidth:k,resetColumns:q}=a({columns:u,columnsState:{persistenceKey:N.resizable,persistenceType:"localStorage"}}),B=s(50,()=>{try{const e=document.querySelector(v),t=document.querySelector(C),o=document.querySelector(".page-layout-footer"),n=o?o.offsetHeight:0;if(t&&e){const o=e.getBoundingClientRect(),r=t.getBoundingClientRect(),s=o.bottom-r.bottom;K(innerHeight-r.top-s-(window.__IN_BASE__?38:22)-n)}}catch(e){window.console.error(e)}});n(()=>{let e,o;return T&&(e=new MutationObserver(e=>e.forEach(()=>B())),o=new ResizeObserver(e=>e.forEach(()=>B())),setTimeout(()=>B(),500),o.observe(document.body),e.observe(document.body,{subtree:!0,childList:!0})),function(){const e=t(),o=localStorage.getItem(d),n=o?t(o):null;if(!n||e.diff(n,"day")>=10){const t=[];for(let e=0;e<localStorage.length;e++){const o=localStorage.key(e);o&&(o.endsWith("#columnState")||o.endsWith("#size")||o.endsWith("#resizable"))&&t.push(o)}t.forEach(e=>{localStorage.removeItem(e)}),localStorage.setItem(d,e.toISOString())}}(),()=>{e&&o&&T&&(o.unobserve(document.body),e.disconnect(document.body))}},[]),n(()=>{!function(e,t){window.localStorage.setItem(m(t).size,e)}(I,y)},[I]);const L=r(()=>(()=>{const e=[...j];p&&e.unshift({...l(i.pagination),fixed:f});const t=e=>({align:g,ellipsis:b,...e,...e.children?{children:e.children.map(t)}:{}});return e.map(t)})(),[j,p,g,b,f,i.pagination]);return c("div",{className:"table-layout card-layout",children:c(e,{ghost:!0,search:!1,scroll:{x:k,y:w||(T?E:void 0)},options:{reload:!1,fullScreen:!0,setting:{checkedReset:!0,extra:c("a",{className:`${$}-pro-table-column-setting-action-rest-button`,onClick:q,children:"重置列宽"})}},components:W,columnsState:{persistenceKey:N.columnState,persistenceType:"localStorage"},onSizeChange:R,columns:L,bordered:!0,size:"small",rowKey:h,...z})})}u.displayName="Table";export{u as default};
