"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DropdownMenuSection = DropdownMenuSection;
exports.default = void 0;
var _DropdownMenuOption = require("./DropdownMenuOption");
var _reactAria = require("../react-aria");
var _jsxRuntime = require("preact/compat/jsx-runtime");
// from react-stately
// from react-aria

function DropdownMenuSection(_ref) {
  let {
    componentClass,
    section,
    state,
    rootId
  } = _ref;
  const {
    itemProps,
    headingProps,
    groupProps
  } = (0, _reactAria.useListBoxSection)({
    heading: section.rendered,
    'aria-label': section['aria-label']
  });
  const headingId = section.props.id ?? `${rootId}__group--${section.index}`;
  const sharedProps = {
    state,
    rootId,
    componentClass
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
      ...itemProps,
      className: `${componentClass}__menu-item-group`,
      children: [section.rendered && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        ...section.props,
        ...headingProps,
        id: headingId,
        className: `${componentClass}__menu-item-group-label`,
        children: section.rendered
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
        ...groupProps,
        "aria-labelledby": headingId,
        children: [...section.childNodes].map(node => /*#__PURE__*/(0, _jsxRuntime.jsx)(_DropdownMenuOption.DropdownMenuOption, {
          item: node,
          ...sharedProps
        }, node.key))
      })]
    })
  });
}
var _default = exports.default = DropdownMenuSection;