"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.NestedTableWSRTable = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _CollectionTableWSRTable = require("../CollectionTable/CollectionTableWSRTable");
var _NestedTableContent = require("./NestedTableContent");
var _useToolbarCollectionSyncProps = require("../ToolbarCollection/useToolbarCollectionSyncProps");
var _useModeTableProps = require("./useModeTableProps");
var _mobx = require("mobx");
var _QuerySearch = require("../QuerySearch");
var _MultiCollectionSupportProvider = require("../MultiCollectionSupportProvider");
var _TablePlaceholderStates = require("../TablePlaceholderStates/TablePlaceholderStates");
var _getVirtualTableProps = require("../Table/getVirtualTableProps");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/NestedTable/NestedTableWSRTable.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _NestedTableWSRTable(props) {
  const {
    state: wrapperState,
    renderError,
    errorState = renderError && ((err, {
      isOnline,
      retry
    }) => renderError == null ? void 0 : renderError({
      err,
      isOnline,
      retry
    })),
    multiLevelSorting,
    actionCell,
    actionCellWidth,
    actionCellProps,
    filters,
    emptyState,
    noResultsState,
    showTitleBar = !wrapperState.container.isPanelLayout,
    horizontalScroll = true,
    rowHeight,
    estimatedRowHeight,
    rowVerticalPadding = 'tiny',
    dragAndDrop,
    dragAndDropBulkSubmit,
    dragAndDropSubmit,
    dragAndDropCancel,
    dragAndDropReorderModeToolbar,
    dragAndDropCategories,
    search = true,
    tabs,
    ...rest
  } = props;
  const {
    toolbar,
    query
  } = wrapperState;
  (0, _react.useState)(() => {
    dragAndDrop == null || dragAndDrop.setStateObject({
      state: wrapperState
    });
  });
  (0, _useToolbarCollectionSyncProps.useToolbarCollectionSyncProps)({
    ...props,
    state: toolbar,
    isUsingDragAndDrop: false,
    isUsingBulkActionsToolbar: false,
    isUsingHorizontalScroll: true,
    isUsingFolders: false,
    isUsingTableVirtualization: true
  });
  const Table = _CollectionTableWSRTable.CollectionTableWSRTable;
  const {
    state,
    key,
    BodyElementType,
    TrElementType,
    columns
  } = (0, _useModeTableProps.useModeTableProps)({
    state: wrapperState,
    horizontalScroll,
    actionCellWidth,
    actionCellProps,
    dragAndDrop
  });
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state.virtual.rowHeight = rowHeight;
    });
  }, [rowHeight, state]);
  (0, _react.useEffect)(() => {
    if (estimatedRowHeight == null) {
      return;
    }
    (0, _mobx.runInAction)(() => {
      state.virtual.estimatedRowHeight = estimatedRowHeight;
    });
  }, [estimatedRowHeight, state]);
  let table = /*#__PURE__*/_react.default.createElement(Table, (0, _extends2.default)({
    rowVerticalPadding: rowVerticalPadding,
    search: search === true ? /*#__PURE__*/_react.default.createElement(_QuerySearch.QuerySearch, {
      state: query.search,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 136,
        columnNumber: 33
      }
    }) : search
  }, rest, {
    skin: "neutral",
    showHeaderWhenEmpty: true,
    sticky: true,
    tabs: tabs,
    filters: filters,
    horizontalScroll: horizontalScroll,
    emptyState: emptyState,
    noResultsState: noResultsState,
    isApplyColumnWidthStyle: true,
    showTitleBar: showTitleBar
  }, (0, _getVirtualTableProps.getVirtualTableProps)({
    horizontalScroll
  }), {
    TrElementType: TrElementType,
    state: state,
    BodyElementType: BodyElementType,
    columns: columns,
    dragAndDropReorderModeToolbar: dragAndDropReorderModeToolbar,
    dragAndDrop: dragAndDrop,
    dragAndDropCancel: dragAndDropCancel,
    dragAndDropSubmit: dragAndDropSubmit,
    dragAndDropBulkSubmit: dragAndDropBulkSubmit,
    dragAndDropCategories: dragAndDropCategories,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 134,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react.default.createElement(_MultiCollectionSupportProvider.MultiCollectionSupportProvider, {
    key: `MultiCollectionSupportProvider_${key}`,
    value: state.multi,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 160,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_TablePlaceholderStates.TablePlaceholderStates, {
    key: `PlaceholderStates_${key}`,
    state: state,
    emptyState: emptyState,
    noResultsState: noResultsState,
    errorState: errorState,
    rowVerticalPadding: rowVerticalPadding,
    showTitleBar: showTitleBar,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 164,
      columnNumber: 9
    }
  }), /*#__PURE__*/_react.default.createElement(_NestedTableContent.NestedTableContent, {
    key: `NestedTableContent_${key}`,
    state: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 173,
      columnNumber: 9
    }
  })));
  if (dragAndDrop) {
    const {
      NestedTableDragAndDropContext
    } = dragAndDrop;
    table = /*#__PURE__*/_react.default.createElement(NestedTableDragAndDropContext, {
      state: wrapperState.nested,
      onSubmit: dragAndDropSubmit,
      onBulkSubmit: dragAndDropBulkSubmit,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 181,
        columnNumber: 7
      }
    }, table);
  }
  return table;
}
const NestedTableWSRTable = exports.NestedTableWSRTable = (0, _mobxReactLite.observer)(_NestedTableWSRTable);
//# sourceMappingURL=NestedTableWSRTable.js.map