"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useNestedModeColumns = useNestedModeColumns;
var _NestedTableParentCell = require("./NestedTableParentCell");
var _react = _interopRequireDefault(require("react"));
var _useCreateWSRColumnBase = require("../../hooks/useCreateWSRColumnBase");
var _useNestedTableActionCell = require("./useNestedTableActionCell");
var _NestedTableMainColumnTitle = require("./NestedTableMainColumnTitle");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/NestedTable/useNestedModeColumns.tsx";
function useNestedModeColumns(props) {
  var _state$mainColumn;
  const {
    state,
    actionCellProps,
    actionCellWidth,
    horizontalScroll,
    dragAndDrop
  } = props;
  const {
    toolbar
  } = state;
  const {
    selectedOrderedColumnsOrAll
  } = toolbar;
  const createWSRColumnBase = (0, _useCreateWSRColumnBase.useCreateWSRColumnBase)({
    horizontalScroll
  });
  const actionCellColumn = (0, _useNestedTableActionCell.useNestedTableActionCell)({
    state: state.nested,
    actionCellWidth,
    actionCellProps
  });
  const mainColumn = {
    key: 'nested-mode-main-column',
    dataHook: 'nested-mode-main-column',
    title: /*#__PURE__*/_react.default.createElement(_NestedTableMainColumnTitle.NestedTableMainColumnTitle, {
      state: state,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 48,
        columnNumber: 12
      }
    }),
    width: ((_state$mainColumn = state.mainColumn) == null ? void 0 : _state$mainColumn.width) || '326px',
    style: undefined,
    render: (keyedItem, rowNum) => {
      if (keyedItem.item.originalKeyedItem) {
        return /*#__PURE__*/_react.default.createElement(_NestedTableParentCell.NestedTableParentCell, {
          state: keyedItem.item.state,
          item: keyedItem.item,
          rowNum: rowNum,
          dragAndDrop: dragAndDrop,
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 54,
            columnNumber: 11
          }
        });
      }
      return null;
    }
  };
  const passedColumns = selectedOrderedColumnsOrAll.map(column => {
    const {
      id,
      sortable
    } = column;
    return {
      ...column,
      sortDescending: sortable && id ? state.query.sort.getIsSortDescending(id) : undefined,
      render: ({
        item
      }, rowNum) => {
        if (item.originalKeyedItem) {
          var _item$state$columns, _item$state$columns$i;
          return (_item$state$columns = item.state.columns) == null || (_item$state$columns$i = _item$state$columns[id]) == null ? void 0 : _item$state$columns$i.call(_item$state$columns, item.originalKeyedItem.item, rowNum);
        }
        return null;
      }
    };
  });
  return [...[mainColumn, ...passedColumns].map((column, index, {
    length
  }) => {
    return {
      ...column,
      ...createWSRColumnBase(column, index, length)
    };
  }), ...(actionCellColumn ? [actionCellColumn] : [])];
}
//# sourceMappingURL=useNestedModeColumns.js.map