'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var cls = require('classnames');
var MenuItem = require('../MenuItem/MenuItem.js');
var NavigationDrawer_tokens = require('../../NavigationDrawer.tokens.js');
var Section_styles = require('./Section.styles.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var cls__default = /*#__PURE__*/_interopDefault(cls);

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 = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
  var _useState = React.useState(false),
    _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
    isCollapsed = _useState2[0],
    setIsCollapsed = _useState2[1];
  var icon = /*#__PURE__*/React__default.default.createElement(Section_styles.SectionIcon, null, /*#__PURE__*/React__default.default.createElement(Section_styles.ArrowIcon, {
    className: cls__default.default(isCollapsed && NavigationDrawer_tokens.classes.navigationDrawerArrowInverse),
    color: "inherit"
  }));
  return /*#__PURE__*/React__default.default.createElement(Section_styles.StyledSection, _rollupPluginBabelHelpers.extends({
    className: className
  }, rest), label ? /*#__PURE__*/React__default.default.createElement(Section_styles.SectionHeader, {
    onClick: function onClick() {
      return setIsCollapsed(!isCollapsed);
    }
  }, withContentLeft && label && icon, isOpen && /*#__PURE__*/React__default.default.createElement(Section_styles.Label, null, label), !withContentLeft && icon) : hasDivider && (_SectionDivider || (_SectionDivider = /*#__PURE__*/React__default.default.createElement(Section_styles.SectionDivider, null))), !isCollapsed && items.map(function (item, index) {
    return /*#__PURE__*/React__default.default.createElement(MenuItem.MenuItem, _rollupPluginBabelHelpers.extends({}, item, {
      key: index,
      withContentLeft: withContentLeft,
      isOpen: isOpen
    }));
  }));
};

exports.Section = Section;
