"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableFoldersContent = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _FolderIcon = require("../FolderIcon");
var _CollectionTableWSRTable = require("../CollectionTable/CollectionTableWSRTable");
var _CollectionTableContent = require("../CollectionTable/CollectionTableContent");
var _VirtualTableRepeater = require("../VirtualGridRepeater/VirtualTableRepeater");
var _VirtualGridStateContext = require("../VirtualGridRepeater/VirtualGridStateContext");
var _useOrFolderActionCellColumn = require("./useOrFolderActionCellColumn");
var _TableFoldersInfiniteScroll = require("./TableFoldersInfiniteScroll");
var _BulkAction = require("../BulkAction");
var _useCreateWSRColumnBase = require("../../hooks/useCreateWSRColumnBase");
var _TablePlaceholderStates = require("../TablePlaceholderStates/TablePlaceholderStates");
var _getVirtualTableProps = require("../Table/getVirtualTableProps");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TableFolders/TableFoldersContent.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 _TableFoldersContent(props) {
  const {
    state,
    columns,
    renderError,
    errorState = renderError && ((err, {
      isOnline,
      retry
    }) => renderError == null ? void 0 : renderError({
      err,
      isOnline,
      retry
    })),
    emptyState,
    noResultsState,
    iconColumn,
    multiLevelSorting,
    actionCell,
    folderActionCell,
    actionCellWidth,
    actionCellProps,
    filters,
    customColumns,
    views,
    bulkActionToolbar,
    bulkActionModal,
    tableGridSwitchButton,
    topNotification,
    search,
    showTitleBar = !state.container.isPanelLayout,
    onRowClick,
    onFolderRowClick,
    selectionDisabled: selectionDisabledProp,
    horizontalScroll = true,
    rowVerticalPadding,
    ...rest
  } = props;
  const actionCellColumn = (0, _useOrFolderActionCellColumn.useOrFolderActionCellColumn)({
    actionCell,
    folderActionCell,
    actionCellWidth,
    actionCellProps: {
      ...(actionCellProps ?? {}),
      stickyActionCell: true
    },
    state: state.collections
  });
  const {
    toolbar: {
      selectedOrderedColumnsOrAll
    }
  } = state;
  const createWSRColumnBase = (0, _useCreateWSRColumnBase.useCreateWSRColumnBase)({
    horizontalScroll
  });
  const finalColumns = [{
    key: 'cairo-avatar',
    title: '',
    width: '48px',
    ...iconColumn,
    style: undefined,
    render: ({
      item
    }, rowNum) => {
      if (item._tag === 'folder') {
        return (iconColumn == null || iconColumn.renderFolder == null ? void 0 : iconColumn.renderFolder(item.originalKeyedItem.item, rowNum)) ?? /*#__PURE__*/_react.default.createElement(_FolderIcon.FolderIcon, {
          "data-hook": "folder-icon",
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 181,
            columnNumber: 15
          }
        });
      }
      return (iconColumn == null || iconColumn.render == null ? void 0 : iconColumn.render(item.originalKeyedItem.item, rowNum)) ?? /*#__PURE__*/_react.default.createElement(_designSystem.Avatar, {
        dataHook: "item-avatar",
        name: state.collections.items.itemName(item.originalKeyedItem.item),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 188,
          columnNumber: 13
        }
      });
    }
  }, ...selectedOrderedColumnsOrAll.map((column, index, {
    length
  }) => {
    const {
      id,
      title,
      width,
      sortable,
      infoTooltipProps,
      render,
      renderFolder,
      ...restColumn
    } = column;
    return {
      ...restColumn,
      ...createWSRColumnBase(column, index, length),
      sortDescending: sortable && id ? state.collections.query.sort.getIsSortDescending(id) : undefined,
      render: (row, rowNum) => {
        const item = row.item;
        if (item._tag === 'folder') {
          return renderFolder == null ? void 0 : renderFolder(item.originalKeyedItem.item, rowNum);
        }
        return render(item.originalKeyedItem.item, rowNum);
      }
    };
  }), ...(actionCellColumn ? [actionCellColumn] : [])];
  const [BodyElementType] = (0, _react.useState)(() => ({
    children
  }) => /*#__PURE__*/_react.default.createElement(_VirtualGridStateContext.VirtualGridStateProvider, {
    value: state.virtual,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 236,
      columnNumber: 11
    }
  }, /*#__PURE__*/_react.default.createElement(_VirtualTableRepeater.VirtualTableRepeater, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 237,
      columnNumber: 13
    }
  }, children)));
  const selectionDisabled = (0, _react.useCallback)(({
    item
  }) => selectionDisabledProp == null ? void 0 : selectionDisabledProp(item), [selectionDisabledProp]);
  if (selectionDisabled != null) {
    state.toolbar.bulk.selectionDisabledProp = selectionDisabled;
  }
  const Table = _CollectionTableWSRTable.CollectionTableWSRTable;
  const showSelection = bulkActionToolbar != null;
  return /*#__PURE__*/_react.default.createElement(Table, (0, _extends2.default)({}, rest, {
    showHeaderWhenEmpty: true,
    state: state,
    sticky: true,
    search: search,
    filters: filters,
    customColumns: customColumns,
    views: views,
    showSelection: showSelection,
    selectionToolbar: bulkActionToolbar && /*#__PURE__*/_react.default.createElement(_BulkAction.MultiCollectionBulkActionToolbar, {
      state: state.toolbar,
      bulkActionToolbar: bulkActionToolbar,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 271,
        columnNumber: 11
      }
    }),
    tableGridSwitchButton: tableGridSwitchButton,
    horizontalScroll: horizontalScroll,
    emptyState: emptyState,
    noResultsState: noResultsState
  }, (0, _getVirtualTableProps.getVirtualTableProps)({
    horizontalScroll
  }), {
    columns: finalColumns,
    showTitleBar: showTitleBar,
    isApplyColumnWidthStyle: true,
    BodyElementType: BodyElementType,
    onSortClick: col => {
      if (col.id != null) {
        state.collections.items.sort({
          id: col.id,
          sortMode: col.sortMode
        }, {
          clearResult: true,
          multiple: multiLevelSorting !== undefined
        });
      }
    },
    onRowClick: (onRowClick || onFolderRowClick) && (({
      item
    }, index) => {
      if (item._tag === 'folder') {
        onFolderRowClick == null || onFolderRowClick(item.originalKeyedItem.item, index);
      } else {
        onRowClick == null || onRowClick(item.originalKeyedItem.item, index);
      }
    }),
    selectionDisabled: selectionDisabledProp && (({
      item
    }) => selectionDisabledProp == null ? void 0 : selectionDisabledProp(item.originalKeyedItem.item)),
    topNotification: topNotification,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 259,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react.default.createElement(_TablePlaceholderStates.TablePlaceholderStates, {
    state: state,
    emptyState: emptyState,
    noResultsState: noResultsState,
    errorState: errorState,
    rowVerticalPadding: rowVerticalPadding,
    showTitleBar: showTitleBar,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 313,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_CollectionTableContent.CollectionTableContent, {
    state: state.table,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 322,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_TableFoldersInfiniteScroll.TableFoldersInfiniteScroll, {
    state: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 323,
      columnNumber: 9
    }
  })));
}
const TableFoldersContent = exports.TableFoldersContent = (0, _mobxReactLite.observer)(_TableFoldersContent);
//# sourceMappingURL=TableFoldersContent.js.map