import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useGlobalTableKeyEvents } from '../hooks/useGlobalTableKeyEvents.js';
import { useInternalTableState } from './table-provider/table-provider.js';
import { RenderRow } from './rows/render-row.js';
const TableBody = () => {
    const { config, state, api } = useInternalTableState();
    // add global key events to the table
    useGlobalTableKeyEvents();
    const canRenderInsertRow = api.canAdd();
    // if can insert rows and we need to add emprty rows, we need to substract 1 because the insert row will occupy one row
    const shouldRenderEmptyRows = canRenderInsertRow
        ? config.data.length < (config.minRowCount ?? 0) - 1
        : config.data.length < (config.minRowCount ?? 0);
    const emptyRowsCount = shouldRenderEmptyRows
        ? (config.minRowCount ?? 0) - config.data.length - (canRenderInsertRow ? 1 : 0)
        : 0;
    return (_jsxs("tbody", { className: "text-sm leading-5 text-gray-900", children: [state.data.map((data, index) => (_jsx(RenderRow, { item: data, rowIndex: index }, JSON.stringify({ data, _reactKeyIndex: index })))), canRenderInsertRow && (_jsx(RenderRow, { item: { data: {}, __index: state.data.length }, rowIndex: config.data.length, mode: "inserting" })), emptyRowsCount > 0 &&
                Array.from({ length: emptyRowsCount }).map((_, index) => (_jsx(RenderRow, { item: { data: {}, __index: state.data.length + 1 + index }, rowIndex: index + config.data.length + (canRenderInsertRow ? 1 : 0), mode: "empty" }, index)))] }));
};
export { TableBody };
//# sourceMappingURL=body.js.map