import React, { useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { runInAction } from 'mobx';
import { VirtualTableRepeater, } from '../VirtualGridRepeater/VirtualTableRepeater';
import { TableBase } from './TableBase';
import { VirtualGridStateProvider } from '../VirtualGridRepeater/VirtualGridStateContext';
import { TableState } from '../../state';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { getVirtualTableProps } from './getVirtualTableProps';
function _TableVirtual(props) {
    const { rowHeight, estimatedRowHeight, horizontalScroll = true } = props;
    const container = useWixPatternsContainer();
    const [state] = useState(() => props.state instanceof TableState
        ? props.state
        : new TableState({
            collection: props.state,
            container,
        }));
    useEffect(() => {
        runInAction(() => {
            state.virtual.rowHeight = rowHeight;
        });
    }, [rowHeight]);
    useEffect(() => {
        if (estimatedRowHeight == null) {
            return;
        }
        runInAction(() => {
            state.virtual.estimatedRowHeight = estimatedRowHeight;
        });
    }, [estimatedRowHeight]);
    const [BodyElementType] = useState(() => ({ children }) => (React.createElement(VirtualGridStateProvider, { value: state.virtual },
        React.createElement(VirtualTableRepeater, null, children))));
    return (React.createElement(TableBase, { ...props, ...getVirtualTableProps({ horizontalScroll }), state: state, horizontalScroll: horizontalScroll, isApplyColumnWidthStyle: true, BodyElementType: BodyElementType }));
}
export const TableVirtual = observer(_TableVirtual);
//# sourceMappingURL=TableVirtual.js.map