import { useCallback, useRef, useState } from "react";
import { useEventListener } from "ahooks";
const useTableSize = ()=>{
    const [height, setTableHeight] = useState(0);
    const [width, setTableWidth] = useState(0);
    const elementRef = useRef(null);
    const calcTableSize = 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.getBoundingClientRect().height) || 0;
        const tableContentRect = null == (_elementRef_current_querySelector1 = elementRef.current.querySelector('.ant-table')) ? 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.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();
    };
    useEventListener('resize', calcTableSize);
    return {
        height,
        width,
        tableSizeRefCallback
    };
};
export { useTableSize };
