"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableSections = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _CollectionTable = require("../CollectionTable");
var _useTableSectionRow = require("./useTableSectionRow");
var _TableSectionsState = require("./TableSectionsState");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TableSections/TableSections.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); }
const _TableSections = ({
  renderSection,
  table,
  columns,
  rowDetails,
  ...collectionTableProps
}) => {
  const [state] = (0, _react.useState)(() => new _TableSectionsState.TableSectionsState(table, renderSection));
  const columnsWithSections = (0, _react.useMemo)(() => columns.map(column => ({
    ...column,
    render: (item, rowNum) => {
      const keyedItem = state.sectionsKeyedItems[rowNum];
      if (keyedItem && state.isSectionRow(keyedItem)) {
        return null;
      }
      return column.render(item, rowNum);
    }
  })), [columns]);
  const wrappedRowDetails = (0, _react.useMemo)(() => {
    if (!rowDetails) {
      return undefined;
    }
    return (rowData, rowNum) => {
      if (state.isSectionRow(rowData)) {
        return null;
      }
      return rowDetails(rowData, rowNum);
    };
  }, [rowDetails, state]);
  const TableSectionsTrElement = (0, _useTableSectionRow.useTableSectionRow)(state);
  return /*#__PURE__*/_react.default.createElement(_CollectionTable.CollectionTable, (0, _extends2.default)({}, collectionTableProps, {
    rowDetails: wrappedRowDetails,
    state: state.table,
    columns: columnsWithSections,
    keyedItems: state.sectionsKeyedItems,
    TrElementType: TableSectionsTrElement,
    isRowDisabled: keyedItem => {
      return state.isSectionRow(keyedItem);
    },
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 56,
      columnNumber: 5
    }
  }));
};
const TableSections = exports.TableSections = (0, _mobxReactLite.observer)(_TableSections);
//# sourceMappingURL=TableSections.js.map