import { useState } from 'react';
import AccordionItem from './AccordionItem/AccordionItem.mjs';
import { jsx, Fragment } from 'react/jsx-runtime';

const Accordion = ({
  indexOpen = -1,
  items,
  onClick,
  theme = 'light'
}) => {
  const [itemsOpen, setItemsOpen] = 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__*/jsx(Fragment, {
    children: items.map((item, index) => /*#__PURE__*/jsx(AccordionItem, {
      open: itemsOpen[index],
      title: item.title,
      subtitle: item.subtitle,
      content: item.content,
      icon: item.icon,
      onClick: () => handleOnClick(index)
    }, item.id || index))
  });
};

export { Accordion as default };
//# sourceMappingURL=Accordion.mjs.map
