import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { useState } from 'react';
import cls from 'classnames';
import { MenuItem } from '../MenuItem/MenuItem.js';
import { classes } from '../../NavigationDrawer.tokens.js';
import { SectionIcon, ArrowIcon, StyledSection, SectionHeader, Label, SectionDivider } from './Section.styles.js';

var _SectionDivider;
var _excluded = ["items", "label", "withContentLeft", "isOpen", "className", "hasDivider"];
var Section = function Section(_ref) {
  var items = _ref.items,
    label = _ref.label,
    withContentLeft = _ref.withContentLeft,
    isOpen = _ref.isOpen,
    className = _ref.className,
    _ref$hasDivider = _ref.hasDivider,
    hasDivider = _ref$hasDivider === void 0 ? false : _ref$hasDivider,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isCollapsed = _useState2[0],
    setIsCollapsed = _useState2[1];
  var icon = /*#__PURE__*/React__default.createElement(SectionIcon, null, /*#__PURE__*/React__default.createElement(ArrowIcon, {
    className: cls(isCollapsed && classes.navigationDrawerArrowInverse),
    color: "inherit"
  }));
  return /*#__PURE__*/React__default.createElement(StyledSection, _extends({
    className: className
  }, rest), label ? /*#__PURE__*/React__default.createElement(SectionHeader, {
    onClick: function onClick() {
      return setIsCollapsed(!isCollapsed);
    }
  }, withContentLeft && label && icon, isOpen && /*#__PURE__*/React__default.createElement(Label, null, label), !withContentLeft && icon) : hasDivider && (_SectionDivider || (_SectionDivider = /*#__PURE__*/React__default.createElement(SectionDivider, null))), !isCollapsed && items.map(function (item, index) {
    return /*#__PURE__*/React__default.createElement(MenuItem, _extends({}, item, {
      key: index,
      withContentLeft: withContentLeft,
      isOpen: isOpen
    }));
  }));
};

export { Section };
