import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_ahooks__ from "ahooks";
const useTableSize = ()=>{
    const [height, setTableHeight] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
    const [width, setTableWidth] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
    const elementRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
    const calcTableSize = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
        var _elementRef_current_querySelector, _elementRef_current_querySelector1, _elementRef_current_querySelector2;
        if (!elementRef.current) return;
        const clientRect = elementRef.current.getBoundingClientRect();
        const tableHeight = Math.ceil((null == clientRect ? void 0 : clientRect.height) || 0);
        const headerHeight = (null === (_elementRef_current_querySelector = elementRef.current.querySelector('.ant-table-header')) || void 0 === _elementRef_current_querySelector ? void 0 : _elementRef_current_querySelector.getBoundingClientRect().height) || 0;
        const tableContentRect = null === (_elementRef_current_querySelector1 = elementRef.current.querySelector('.ant-table')) || void 0 === _elementRef_current_querySelector1 ? void 0 : _elementRef_current_querySelector1.getBoundingClientRect();
        if (!tableContentRect) return;
        const paginationRect = null === (_elementRef_current_querySelector2 = elementRef.current.querySelector('.ant-table-pagination')) || void 0 === _elementRef_current_querySelector2 ? void 0 : _elementRef_current_querySelector2.getBoundingClientRect();
        const paginationHeight = paginationRect ? paginationRect.y - tableContentRect.height - tableContentRect.y + paginationRect.height : 0;
        setTableWidth(clientRect.width);
        setTableHeight(tableHeight - headerHeight - paginationHeight);
    }, []);
    const tableSizeRefCallback = (ref)=>{
        elementRef.current = ref && ref.children ? ref.children[0] : null;
        calcTableSize();
    };
    (0, __WEBPACK_EXTERNAL_MODULE_ahooks__.useEventListener)('resize', calcTableSize);
    return {
        height,
        width,
        tableSizeRefCallback
    };
};
export { useTableSize };
