import React from 'react';
import classnames from 'classnames';
import isNil from 'lodash-es/isNil';
import DropdownItem from './dropdown-item';
import DropdownMenuMultiLevelOptions from './dropdown-menu-multi-level-options';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/** Dropdown content list with section titles */
export const DropdownSectionedContentList = ({
  options,
  selectedKey,
  contentTestId,
  contentClassName,
  onSelect,
  onCloseDropdown,
  labelledBy,
  isMultiLevelSectioned,
  multiLevelProps,
  LinkComponent
}) => {
  const shouldRenderMultiLevel = isMultiLevelSectioned && !!multiLevelProps;
  return /*#__PURE__*/_jsx("ul", {
    className: classnames('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__*/_jsxs(React.Fragment, {
        children: [(option.title || index !== 0) && /*#__PURE__*/_jsx("li", {
          className: classnames('title uppercased', option.title && 'extra-padding-bottom'),
          "test-id": option.testId,
          role: "separator",
          children: option.title
        }, index), shouldRenderMultiLevel ? option.subOptions?.map((subOption, i) => /*#__PURE__*/_jsx(DropdownMenuMultiLevelOptions, {
          onSelect: onSelect,
          closeDropdown: onCloseDropdown,
          option: subOption,
          ...multiLevelProps
        }, subOption.key || `${i}-${subOption.title}`)) : option.subOptions?.map((subOption, i) => /*#__PURE__*/_jsx(DropdownItem, {
          option: subOption,
          selectedKey: selectedKey,
          onCloseDropdown: onCloseDropdown,
          onSelect: onSelect,
          LinkComponent: LinkComponent
        }, isNil(subOption.key) ? i : subOption.key))]
      }, index);
    })
  });
};

/** Dropdown content list */
const DropdownContentList = ({
  options,
  selectedKey,
  contentTestId,
  onSelect,
  onCloseDropdown,
  contentClassName,
  labelledBy,
  LinkComponent
}) => {
  return /*#__PURE__*/_jsx("ul", {
    className: classnames('dropdown-menu-list', contentClassName),
    role: "menu",
    "test-id": contentTestId,
    "aria-labelledby": labelledBy,
    tabIndex: -1,
    children: options.map((option, index) => /*#__PURE__*/_jsx(DropdownItem, {
      option: option,
      selectedKey: selectedKey,
      onCloseDropdown: onCloseDropdown,
      onSelect: onSelect,
      LinkComponent: LinkComponent
    }, isNil(option.key) ? index : option.key))
  });
};
export default DropdownContentList;