import React, { useRef, useEffect } from "react";
import { StyledStartMenuTitle, StyledStartMenuListItem, StyledStartMenuList, StyledStartMenuNoResults } from "./Styles";
import { useResizeObserver } from "../../utils";
import { Badge } from "../Badge";
import { ArrowRightIcon } from "../Icons";
export const StartMenu = _ref => {
  let {
    data,
    selected,
    onItemClick,
    style,
    onHeightChange,
    shouldRenderSubmenus,
    emptyFilterText,
    children
  } = _ref;
  const ref = useRef(null);
  const dimensions = useResizeObserver(ref);
  const height = dimensions == null ? void 0 : dimensions.height;
  useEffect(() => {
    if (height && height > 0) {
      onHeightChange(height);
    }
  }, [height, onHeightChange]);
  return /*#__PURE__*/React.createElement("div", {
    style: style,
    ref: ref
  }, /*#__PURE__*/React.createElement(StyledStartMenuList, null, shouldRenderSubmenus ? data.map((_ref2, index) => {
    let {
      id,
      title,
      submenu
    } = _ref2;
    let 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 ? void 0 : _selected$id.length;
    }
    if ((submenu == null ? void 0 : submenu.length) > 1) {
      return /*#__PURE__*/React.createElement(StyledStartMenuListItem, {
        key: "filter-list-item-" + index,
        onClick: () => onItemClick(id)
      }, /*#__PURE__*/React.createElement(StyledStartMenuTitle, null, title), count > 0 ? /*#__PURE__*/React.createElement(Badge, {
        dimension: 16,
        value: count,
        isStandalone: true
      }) : null, /*#__PURE__*/React.createElement(ArrowRightIcon, null));
    }
  }) : emptyFilterText ? /*#__PURE__*/React.createElement(StyledStartMenuNoResults, null, emptyFilterText) : null, children));
};
//# sourceMappingURL=StartMenu.js.map