"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.buildMobileColumns = buildMobileColumns;
var _react = _interopRequireDefault(require("react"));
var _designSystem = require("@wix/design-system");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionTable/buildMobileColumns.tsx";
function isFirstColumnMobileConfig(col) {
  var _col$mobile;
  return ((_col$mobile = col.mobile) == null ? void 0 : _col$mobile.column) === 'first';
}
function buildMobileColumns(columns) {
  const hasMobileConfig = columns.some(col => {
    var _mobile;
    return (_mobile = col.mobile) == null ? void 0 : _mobile.column;
  });
  if (!hasMobileConfig) {
    return [{
      id: 'tableColumn',
      title: '',
      render: (params, index) => {
        var _columns$0$render, _columns$, _columns$1$render, _columns$2;
        return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
          direction: "vertical",
          gap: "SP1",
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 23,
            columnNumber: 11
          }
        }, columns[0] && /*#__PURE__*/_react.default.createElement("div", {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 24,
            columnNumber: 28
          }
        }, (_columns$0$render = (_columns$ = columns[0]).render) == null ? void 0 : _columns$0$render.call(_columns$, params, index)), columns[1] && /*#__PURE__*/_react.default.createElement("div", {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 25,
            columnNumber: 28
          }
        }, (_columns$1$render = (_columns$2 = columns[1]).render) == null ? void 0 : _columns$1$render.call(_columns$2, params, index)));
      }
    }];
  }
  const firstColumns = columns.filter(isFirstColumnMobileConfig).sort((a, b) => {
    var _a$mobile, _b$mobile;
    const orderA = ((_a$mobile = a.mobile) == null ? void 0 : _a$mobile.order) ?? Infinity;
    const orderB = ((_b$mobile = b.mobile) == null ? void 0 : _b$mobile.order) ?? Infinity;
    return orderA - orderB;
  });
  const secondColumn = columns.find(col => {
    var _col$mobile2;
    return ((_col$mobile2 = col.mobile) == null ? void 0 : _col$mobile2.column) === 'second';
  });
  const result = [];
  if (firstColumns.length > 0) {
    result.push({
      id: 'mobile-first-column',
      title: '',
      render: (params, index) => /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        direction: "vertical",
        gap: "SP1",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 49,
          columnNumber: 9
        }
      }, firstColumns.map((col, colIndex) => /*#__PURE__*/_react.default.createElement("div", {
        key: `first-col-${colIndex}`,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 51,
          columnNumber: 13
        }
      }, col.render == null ? void 0 : col.render(params, index))))
    });
  }
  if (secondColumn) {
    result.push({
      id: 'mobile-second-column',
      title: '',
      render: (params, index) => secondColumn.render == null ? void 0 : secondColumn.render(params, index)
    });
  }
  return result;
}
//# sourceMappingURL=buildMobileColumns.js.map