"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = require("react");
var _useRowSelection = _interopRequireDefault(require("./useRowSelection"));
var _useRowActions = _interopRequireDefault(require("./useRowActions"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
var _default = exports["default"] = function _default(dataColumns, _ref) {
  var rowActions = _ref.rowActions,
    enableSelection = _ref.enableSelection,
    singleRowSelection = _ref.singleRowSelection,
    enableResizing = _ref.enableResizing,
    enableSorting = _ref.enableSorting,
    testPrefix = _ref.testPrefix,
    tableMeta = _ref.tableMeta;
  var rowActionsColumn = (0, _useRowActions["default"])(rowActions, {
    testPrefix: testPrefix,
    tableMeta: tableMeta
  });
  var selectionColumn = (0, _useRowSelection["default"])(enableSelection, {
    testPrefix: testPrefix,
    tableMeta: tableMeta,
    singleRowSelection: singleRowSelection
  });
  return (0, _react.useMemo)(function () {
    if (!dataColumns || dataColumns.length < 1) return [];
    var isGrouped = false;
    dataColumns = dataColumns.map(function (col, index) {
      if (Array.isArray(col.columns)) {
        isGrouped = true;
        return _extends({
          id: index
        }, col, {
          columns: col.columns.map(function (subCol, index) {
            if (!subCol.id) throw new Error("Please provide id at " + index);
            return _extends({
              enableColumnFilter: false,
              enableGlobalFilter: true,
              enableSorting: enableSorting,
              enableMultiSort: enableSorting
            }, enableResizing ? {
              size: 120,
              maxSize: 5000,
              minSize: 60
            } : {}, {
              enableHiding: true,
              enableResizing: enableResizing,
              footer: function footer(props) {
                return props.column.id;
              },
              tableMeta: tableMeta
            }, subCol, {
              accessorKey: subCol.accessorKey || subCol.id
            });
          })
        });
      }
      if (!col.id) throw new Error("Please provide id at " + index);
      return _extends({
        enableColumnFilter: false,
        enableGlobalFilter: true,
        enableSorting: enableSorting,
        enableMultiSort: enableSorting
      }, enableResizing ? {
        size: 120,
        maxSize: 5000,
        minSize: 10
      } : {}, {
        enableHiding: true,
        enableResizing: enableResizing,
        footer: function footer(props) {
          return props.column.id;
        },
        tableMeta: tableMeta
      }, col, {
        accessorKey: col.accessorKey || col.id
      });
    });
    if (selectionColumn) dataColumns.unshift(isGrouped ? {
      id: "selectionColumn",
      isPlaceholder: true,
      size: selectionColumn.size,
      columns: [selectionColumn]
    } : selectionColumn);
    if (rowActionsColumn) dataColumns.push(isGrouped ? {
      id: "rowActionsColumn",
      isPlaceholder: true,
      size: rowActionsColumn.size,
      columns: [rowActionsColumn]
    } : rowActionsColumn);
    return dataColumns;
  }, [dataColumns, rowActionsColumn, selectionColumn]);
};