'use strict';

var slicedToArray = require('./slicedToArray-067dd3bc.js');
var React = require('react');
var Accordion = require('react-bootstrap/Accordion');
var AccordionToggle = require('react-bootstrap/AccordionToggle');
var index_esm = require('./index.esm-d81454e7.js');
require('./_commonjsHelpers-06173234.js');
require('./web.dom.iterable-d98303e0.js');
require('./core.get-iterator-method-5643aa10.js');
require('./iconBase-be4097c0.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Accordion__default = /*#__PURE__*/_interopDefaultLegacy(Accordion);

var AccordionPanel = function AccordionPanel(props) {
  var accordionClassName = props.accordionClassName,
      data = props.data;

  var _useState = React.useState('0'),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      activeAccordionKey = _useState2[0],
      setaAtiveAccordionKey = _useState2[1];

  var handleAccordion = function handleAccordion(id) {
    setaAtiveAccordionKey(id);
  };

  var CustomToggle = function CustomToggle(_ref) {
    var children = _ref.children,
        eventKey = _ref.eventKey;

    var decoratedOnClick = AccordionToggle.useAccordionToggle(eventKey, function () {
      return handleAccordion(eventKey);
    });
    return React__default["default"].createElement(
      'div',
      { onMouseEnter: decoratedOnClick, className: 'accordion-head' },
      children
    );
  };

  return React__default["default"].createElement(
    React__default["default"].Fragment,
    null,
    data && data.length && React__default["default"].createElement(
      Accordion__default["default"],
      { defaultActiveKey: '0', activeKey: activeAccordionKey, className: accordionClassName },
      data.map(function (item) {
        return React__default["default"].createElement(
          React__default["default"].Fragment,
          null,
          React__default["default"].createElement(
            CustomToggle,
            { key: item.id, eventKey: item.id },
            React__default["default"].createElement(
              'a',
              { href: item.url },
              React__default["default"].createElement(
                React__default["default"].Fragment,
                null,
                item.title,
                item.subItems && React__default["default"].createElement(index_esm.IoMdArrowDropdown, null)
              )
            )
          ),
          React__default["default"].createElement(
            Accordion__default["default"].Collapse,
            { eventKey: item.id },
            React__default["default"].createElement(
              'div',
              null,
              item.subItems && item.subItems.map(function (subItem) {
                return React__default["default"].createElement(
                  'a',
                  { href: subItem.url },
                  React__default["default"].createElement(
                    'div',
                    { key: subItem.id, className: 'accordion-sub-item' },
                    subItem.title
                  )
                );
              })
            )
          )
        );
      })
    )
  );
};

module.exports = AccordionPanel;
