function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from "preact/compat";
import { DropdownMenuOption } from "./DropdownMenuOption";
// from react-stately
import { useListBoxSection } from "../react-aria"; // from react-aria

export function DropdownMenuSection(_ref) {
  var _section$props$id;
  var componentClass = _ref.componentClass,
    section = _ref.section,
    state = _ref.state,
    rootId = _ref.rootId;
  var _useListBoxSection = useListBoxSection({
      heading: section.rendered,
      'aria-label': section['aria-label']
    }),
    itemProps = _useListBoxSection.itemProps,
    headingProps = _useListBoxSection.headingProps,
    groupProps = _useListBoxSection.groupProps;
  var headingId = (_section$props$id = section.props.id) !== null && _section$props$id !== void 0 ? _section$props$id : "".concat(rootId, "__group--").concat(section.index);
  var sharedProps = {
    state: state,
    rootId: rootId,
    componentClass: componentClass
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("li", _extends({}, itemProps, {
    className: "".concat(componentClass, "__menu-item-group")
  }), section.rendered && /*#__PURE__*/React.createElement("div", _extends({}, section.props, headingProps, {
    id: headingId,
    className: "".concat(componentClass, "__menu-item-group-label")
  }), section.rendered), /*#__PURE__*/React.createElement("ul", _extends({}, groupProps, {
    "aria-labelledby": headingId
  }), _toConsumableArray(section.childNodes).map(function (node) {
    return /*#__PURE__*/React.createElement(DropdownMenuOption, _extends({
      key: node.key,
      item: node
    }, sharedProps));
  }))));
}
export default DropdownMenuSection;