"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _chunk = _interopRequireDefault(require("lodash/chunk"));
var _AnalyticsLayoutSt = require("./AnalyticsLayout.st.css.js");
var _Cell = _interopRequireDefault(require("./Cell/Cell"));
var _deprecationLog = _interopRequireDefault(require("../utils/deprecationLog"));
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/AnalyticsLayout/AnalyticsLayout.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(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 (var _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); }
var MIN_ITEMS_PER_ROW = 2;
var MAX_ITEMS_PER_ROW = 3;
function _splitItemsToRows(items, min, max) {
  var mod = items.length % max;
  if (mod < min && mod !== 0) {
    var numberOfItemsForFillsMaxRows = max * (Math.floor(items.length / max) - 1);
    var ItemsForFillsMaxRows = items.splice(0, numberOfItemsForFillsMaxRows);
    return [...(0, _chunk.default)(ItemsForFillsMaxRows, max), ...(0, _chunk.default)(items, min)];
  } else {
    return (0, _chunk.default)(items, max);
  }
}

/** AnalyticsLayout */
class AnalyticsLayout extends React.PureComponent {
  render() {
    var _this$props$showDivid;
    var {
      dataHook,
      items,
      minItemsPerRow,
      maxItemsPerRow,
      divider,
      className,
      children
    } = this.props;
    var itemsSplitToRows = _splitItemsToRows(items, minItemsPerRow, maxItemsPerRow);
    var showDivider = (_this$props$showDivid = this.props.showDivider) !== null && _this$props$showDivid !== void 0 ? _this$props$showDivid : divider;
    if (divider) {
      (0, _deprecationLog.default)('<AnalyticsLayout/> - prop "divider" is deprecated and will be removed in next major release, please use "showDivider" property instead.');
    }
    return /*#__PURE__*/React.createElement("div", {
      className: (0, _AnalyticsLayoutSt.st)(_AnalyticsLayoutSt.classes.root, className),
      "data-hook": dataHook,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 60,
        columnNumber: 7
      }
    }, itemsSplitToRows.map((row, indexKey) => {
      return /*#__PURE__*/React.createElement("div", {
        key: indexKey,
        className: (0, _AnalyticsLayoutSt.st)(_AnalyticsLayoutSt.classes.row, {
          showDivider
        }),
        style: {
          gridTemplateColumns: "repeat(".concat(row.length, ", 1fr)")
        },
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 63,
          columnNumber: 13
        }
      }, row.map((item, index) => {
        return children(item, index, row.length);
      }));
    }));
  }
}
AnalyticsLayout.displayName = 'AnalyticsLayout';
AnalyticsLayout.defaultProps = {
  items: [],
  minItemsPerRow: MIN_ITEMS_PER_ROW,
  maxItemsPerRow: MAX_ITEMS_PER_ROW,
  divider: true // TODO: add default value to showDivider once divider is removed
};
AnalyticsLayout.Cell = _Cell.default;
var _default = exports.default = AnalyticsLayout;
//# sourceMappingURL=AnalyticsLayout.js.map