"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StartMenu = void 0;
var _react = _interopRequireWildcard(require("react"));
var _Styles = require("./Styles");
var _utils = require("../../utils");
var _Badge = require("../Badge");
var _Icons = require("../Icons");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var StartMenu = exports.StartMenu = function StartMenu(_ref) {
  var data = _ref.data,
    selected = _ref.selected,
    onItemClick = _ref.onItemClick,
    style = _ref.style,
    onHeightChange = _ref.onHeightChange,
    shouldRenderSubmenus = _ref.shouldRenderSubmenus,
    emptyFilterText = _ref.emptyFilterText,
    children = _ref.children;
  var ref = (0, _react.useRef)(null);
  var dimensions = (0, _utils.useResizeObserver)(ref);
  var height = dimensions === null || dimensions === void 0 ? void 0 : dimensions.height;
  (0, _react.useEffect)(function () {
    if (height && height > 0) {
      onHeightChange(height);
    }
  }, [height, onHeightChange]);
  return /*#__PURE__*/_react.default.createElement("div", {
    style: style,
    ref: ref
  }, /*#__PURE__*/_react.default.createElement(_Styles.StyledStartMenuList, null, shouldRenderSubmenus ? data.map(function (_ref2, index) {
    var id = _ref2.id,
      title = _ref2.title,
      submenu = _ref2.submenu;
    var count = 0;
    // Popricati o ovome kada je selected[id] vrednost 0.
    if (typeof selected[id] === "string") {
      count += 1;
    } else {
      var _selected$id;
      count = (_selected$id = selected[id]) === null || _selected$id === void 0 ? void 0 : _selected$id.length;
    }
    if ((submenu === null || submenu === void 0 ? void 0 : submenu.length) > 1) {
      return /*#__PURE__*/_react.default.createElement(_Styles.StyledStartMenuListItem, {
        key: "filter-list-item-".concat(index),
        onClick: function onClick() {
          return onItemClick(id);
        }
      }, /*#__PURE__*/_react.default.createElement(_Styles.StyledStartMenuTitle, null, title), count > 0 ? /*#__PURE__*/_react.default.createElement(_Badge.Badge, {
        dimension: 16,
        value: count,
        isStandalone: true
      }) : null, /*#__PURE__*/_react.default.createElement(_Icons.ArrowRightIcon, null));
    }
  }) : emptyFilterText ? /*#__PURE__*/_react.default.createElement(_Styles.StyledStartMenuNoResults, null, emptyFilterText) : null, children));
};
//# sourceMappingURL=StartMenu.js.map