import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-a4107da3.js';
import './es6.string.iterator-c990c18c.js';
import './core.get-iterator-method-e1de7503.js';
import './web.dom.iterable-4439f05a.js';
import React__default, { useState } from 'react';
import { _ as _slicedToArray } from './slicedToArray-641f241f.js';
import './iconBase-602d52fe.js';
import { a as IoMdArrowDropdown } from './index.esm-29e48d38.js';
import Accordion from 'react-bootstrap/Accordion';
import { useAccordionToggle } from 'react-bootstrap/AccordionToggle';

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

  var _useState = useState('0'),
      _useState2 = _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 = useAccordionToggle(eventKey, function () {
      return handleAccordion(eventKey);
    });
    return React__default.createElement(
      'div',
      { onMouseEnter: decoratedOnClick, className: 'accordion-head' },
      children
    );
  };

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

export default AccordionPanel;
