"use strict";

exports.__esModule = true;
exports.useTableCollectionSyncProps = useTableCollectionSyncProps;
var _react = require("react");
var _useToolbarCollectionSyncProps = require("../ToolbarCollection/useToolbarCollectionSyncProps");
var _assertComponentType = require("../assertComponentType");
var _useColumnsSyncProps = require("../../hooks/useColumnsSyncProps");
var _isValidElement = require("../isValidElement");
function useTableCollectionSyncProps(props) {
  const {
    state: table,
    customColumns,
    columns: tableColumns,
    showSelection,
    actionCell,
    multiLevelSorting,
    views,
    selectionDisabled,
    checkboxTooltipContent,
    dataExtension,
    isUsingTableVirtualization,
    isUsingExpandCollapse,
    dragAndDropReorderModeToolbar
  } = props;
  (0, _assertComponentType.assertComponentType)(customColumns, 'CustomColumns', 'customColumns');
  (0, _assertComponentType.assertComponentType)(multiLevelSorting, 'MultiLevelSorting', 'multiLevelSorting');
  (0, _assertComponentType.assertComponentType)(views, 'CollectionViewsDropdown', 'views');
  (0, _assertComponentType.assertComponentType)(dragAndDropReorderModeToolbar, 'ReorderModeToolbar', 'dragAndDropReorderModeToolbar');
  const state = table.toolbar;
  (0, _useToolbarCollectionSyncProps.useToolbarCollectionSyncProps)({
    ...props,
    state,
    isUsingDragAndDrop: !!props.dragAndDrop,
    isUsingBulkActionsToolbar: !!props.bulkActionToolbar,
    isUsingHorizontalScroll: props.horizontalScroll ?? false,
    isUsingFolders: false,
    isUsingTableVirtualization,
    isUsingExpandCollapse
  });
  (0, _useColumnsSyncProps.useColumnsSyncProps)({
    toolbar: state,
    customColumns,
    columns: tableColumns
  });
  (0, _react.useState)(() => {
    if ((0, _isValidElement.isValidElement)(dataExtension)) {
      dataExtension.type.setDataExtensionOnTable(state, dataExtension.props);
    } else {
      dataExtension == null || dataExtension.setDataExtensionOnTable(state);
    }
  });
  (0, _react.useEffect)(() => {
    if (!dataExtension) {
      return;
    }
    ((0, _isValidElement.isValidElement)(dataExtension) ? dataExtension.type : dataExtension).syncTableCollectionProps(state);
  }, []);
  (0, _react.useEffect)(() => {
    if (!dragAndDropReorderModeToolbar) {
      return;
    }
    dragAndDropReorderModeToolbar == null || dragAndDropReorderModeToolbar.type.setReorderModeState(state);
  }, [state._dnd, dragAndDropReorderModeToolbar]);
  (0, _react.useEffect)(() => state.selectionProps.set({
    showSelection
  }), [showSelection]);
  (0, _react.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