'use strict';

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

var React = require('react');
var AccordionItem = require('./AccordionItem/AccordionItem.js');
var jsxRuntime = require('react/jsx-runtime');

const Accordion = ({
  indexOpen = -1,
  items,
  onClick,
  theme = 'light'
}) => {
  const [itemsOpen, setItemsOpen] = React.useState(() => items.map((value, index) => index === indexOpen));
  /**
   * Handles a click event on an accordion item.
   *
   * @param index The index of the item that was clicked.
   */
  const handleOnClick = index => {
    if (onClick) {
      onClick(index);
    }
    const newItems = [...itemsOpen];
    newItems[index] = !itemsOpen[index];
    setItemsOpen(newItems);
  };
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
    children: items.map((item, index) => /*#__PURE__*/jsxRuntime.jsx(AccordionItem.default, {
      open: itemsOpen[index],
      title: item.title,
      subtitle: item.subtitle,
      content: item.content,
      icon: item.icon,
      media: item.media,
      showMediaAtAllSizes: item.showMediaAtAllSizes,
      showMediaCircle: item.showMediaCircle,
      isContainerAligned: item.isContainerAligned,
      onClick: () => handleOnClick(index)
    }, item.id || index))
  });
};

exports.default = Accordion;
//# sourceMappingURL=Accordion.js.map
