"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.DropdownSectionedContentList = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _isNil = _interopRequireDefault(require("lodash-es/isNil"));
var _dropdownItem = _interopRequireDefault(require("./dropdown-item"));
var _dropdownMenuMultiLevelOptions = _interopRequireDefault(require("./dropdown-menu-multi-level-options"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/** Dropdown content list with section titles */
const DropdownSectionedContentList = ({
  options,
  selectedKey,
  contentTestId,
  contentClassName,
  onSelect,
  onCloseDropdown,
  labelledBy,
  isMultiLevelSectioned,
  multiLevelProps,
  LinkComponent
}) => {
  const shouldRenderMultiLevel = isMultiLevelSectioned && !!multiLevelProps;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
    className: (0, _classnames.default)('dropdown-menu-list sectioned', contentClassName),
    role: "menu",
    "test-id": contentTestId,
    "aria-labelledby": labelledBy,
    tabIndex: -1,
    children: options.map((option, index) => {
      return option.isShown !== false && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.default.Fragment, {
        children: [(option.title || index !== 0) && /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
          className: (0, _classnames.default)('title uppercased', option.title && 'extra-padding-bottom'),
          "test-id": option.testId,
          role: "separator",
          children: option.title
        }, index), shouldRenderMultiLevel ? option.subOptions?.map((subOption, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownMenuMultiLevelOptions.default, {
          onSelect: onSelect,
          closeDropdown: onCloseDropdown,
          option: subOption,
          ...multiLevelProps
        }, subOption.key || `${i}-${subOption.title}`)) : option.subOptions?.map((subOption, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItem.default, {
          option: subOption,
          selectedKey: selectedKey,
          onCloseDropdown: onCloseDropdown,
          onSelect: onSelect,
          LinkComponent: LinkComponent
        }, (0, _isNil.default)(subOption.key) ? i : subOption.key))]
      }, index);
    })
  });
};

/** Dropdown content list */
exports.DropdownSectionedContentList = DropdownSectionedContentList;
const DropdownContentList = ({
  options,
  selectedKey,
  contentTestId,
  onSelect,
  onCloseDropdown,
  contentClassName,
  labelledBy,
  LinkComponent
}) => {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
    className: (0, _classnames.default)('dropdown-menu-list', contentClassName),
    role: "menu",
    "test-id": contentTestId,
    "aria-labelledby": labelledBy,
    tabIndex: -1,
    children: options.map((option, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItem.default, {
      option: option,
      selectedKey: selectedKey,
      onCloseDropdown: onCloseDropdown,
      onSelect: onSelect,
      LinkComponent: LinkComponent
    }, (0, _isNil.default)(option.key) ? index : option.key))
  });
};
var _default = exports.default = DropdownContentList;