"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useFlatModeColumns = useFlatModeColumns;
var _react = _interopRequireDefault(require("react"));
var _useCreateWSRColumnBase = require("../../hooks/useCreateWSRColumnBase");
var _NestedTableFlatModeMainCell = require("./NestedTableFlatModeMainCell");
var _useNestedTableActionCell = require("./useNestedTableActionCell");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/NestedTable/useFlatModeColumns.tsx";
function useFlatModeColumns(props) {
  const {
    state,
    actionCellProps,
    actionCellWidth,
    horizontalScroll
  } = props;
  const {
    toolbar
  } = state;
  const {
    selectedOrderedColumnsOrAll
  } = toolbar;
  const createWSRColumnBase = (0, _useCreateWSRColumnBase.useCreateWSRColumnBase)({
    horizontalScroll
  });
  const actionCellColumn = (0, _useNestedTableActionCell.useNestedTableActionCell)({
    state: state.flat,
    actionCellWidth,
    actionCellProps
  });
  const mainColumn = {
    key: 'flat-mode-main-column',
    dataHook: 'flat-mode-main-column',
    title: '',
    width: '326px',
    ...state.mainColumn,
    style: undefined,
    render: ({
      item
    }, rowNum) => /*#__PURE__*/_react.default.createElement(_NestedTableFlatModeMainCell.NestedTableFlatModeMainCell, {
      item: item,
      rowNum: rowNum,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 45,
        columnNumber: 7
      }
    })
  };
  const passedColumns = selectedOrderedColumnsOrAll.map(column => {
    const {
      id,
      sortable
    } = column;
    return {
      ...column,
      sortDescending: sortable && id ? state.query.sort.getIsSortDescending(id) : undefined,
      render: ({
        item
      }, rowNum) => {
        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 [...[mainColumn, ...passedColumns].map((column, index, {
    length
  }) => {
    return {
      ...column,
      ...createWSRColumnBase(column, index, length)
    };
  }), ...(actionCellColumn ? [actionCellColumn] : [])];
}
//# sourceMappingURL=useFlatModeColumns.js.map