import { useEffect, useState } from 'react';
import { useToolbarCollectionSyncProps } from '../ToolbarCollection/useToolbarCollectionSyncProps';
import { assertComponentType } from '../assertComponentType';
import { useColumnsSyncProps } from '../../hooks/useColumnsSyncProps';
import { isValidElement } from '../isValidElement';
export function useTableCollectionSyncProps(props) {
    const { state: table, customColumns, columns: tableColumns, showSelection, actionCell, multiLevelSorting, views, selectionDisabled, checkboxTooltipContent, dataExtension, isUsingTableVirtualization, isUsingExpandCollapse, dragAndDropReorderModeToolbar, } = props;
    assertComponentType(customColumns, 'CustomColumns', 'customColumns');
    assertComponentType(multiLevelSorting, 'MultiLevelSorting', 'multiLevelSorting');
    assertComponentType(views, 'CollectionViewsDropdown', 'views');
    assertComponentType(dragAndDropReorderModeToolbar, 'ReorderModeToolbar', 'dragAndDropReorderModeToolbar');
    const state = table.toolbar;
    useToolbarCollectionSyncProps({
        ...props,
        state,
        isUsingDragAndDrop: !!props.dragAndDrop,
        isUsingBulkActionsToolbar: !!props.bulkActionToolbar,
        isUsingHorizontalScroll: props.horizontalScroll ?? false,
        isUsingFolders: false,
        isUsingTableVirtualization,
        isUsingExpandCollapse,
    });
    useColumnsSyncProps({
        toolbar: state,
        customColumns,
        columns: tableColumns,
    });
    useState(() => {
        if (isValidElement(dataExtension)) {
            dataExtension.type.setDataExtensionOnTable(state, dataExtension.props);
        }
        else {
            dataExtension?.setDataExtensionOnTable(state);
        }
    });
    useEffect(() => {
        if (!dataExtension) {
            return;
        }
        (isValidElement(dataExtension)
            ? dataExtension.type
            : dataExtension).syncTableCollectionProps(state);
    }, []);
    useEffect(() => {
        if (!dragAndDropReorderModeToolbar) {
            return;
        }
        dragAndDropReorderModeToolbar?.type.setReorderModeState(state);
    }, [state._dnd, dragAndDropReorderModeToolbar]);
    useEffect(() => state.selectionProps.set({ showSelection }), [showSelection]);
    useEffect(() => state.actionCell.set(actionCell), [actionCell]);
    if (selectionDisabled != null) {
        state.bulk.selectionDisabledProp =
            selectionDisabled;
    }
    if (checkboxTooltipContent != null) {
        state.bulk.checkboxTooltipContentProp =
            checkboxTooltipContent;
    }
    return state;
}
//# sourceMappingURL=useTableCollectionSyncProps.js.map