'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

require('./_commonjsHelpers-06173234.js');
require('./_to-object-329a650b.js');
require('./es6.string.iterator-cc0bbaa4.js');
require('./core.get-iterator-method-f62321d4.js');
require('./web.dom.iterable-a0e279c1.js');
var React = require('react');
var React__default = _interopDefault(React);
var slicedToArray = require('./slicedToArray-8f385299.js');
require('./iconBase-68959171.js');
var index_esm = require('./index.esm-876ca9ff.js');
var Accordion = _interopDefault(require('react-bootstrap/Accordion'));
var AccordionToggle = require('react-bootstrap/AccordionToggle');

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.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(index_esm.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
                  )
                );
              })
            )
          )
        );
      })
    )
  );
};

module.exports = AccordionPanel;
