import {
  Accordion
} from "./chunk-7JT4DKQA.js";
import {
  Divider
} from "./chunk-IFXEE4WM.js";

// src/components/Accordion/AccordionList.tsx
import { useState, Fragment } from "react";
import classNames from "classnames/dedupe";
import "@simplybusiness/mobius/src/components/Accordion/AccordionList.css";
import { jsx, jsxs } from "react/jsx-runtime";
var AccordionList = (props) => {
  const {
    className,
    content,
    onOpen,
    onClose,
    allowMultiple = false,
    ...rest
  } = props;
  const [openIds, setOpenIds] = useState(/* @__PURE__ */ new Set());
  const classes = classNames("mobius", "mobius-accordion-list", className);
  const handleAccordionChange = (id, isOpen) => {
    setOpenIds((prev) => {
      const newSet = new Set(prev);
      if (isOpen) {
        if (!allowMultiple) {
          newSet.clear();
        }
        newSet.add(id);
      } else {
        newSet.delete(id);
      }
      return newSet;
    });
    if (isOpen) {
      onOpen?.(id);
    } else {
      onClose?.(id);
    }
  };
  return /* @__PURE__ */ jsx("div", { className: classes, ...rest, children: content.map((item, index) => {
    const { id, header, details } = item;
    const isOpen = openIds.has(id);
    return /* @__PURE__ */ jsxs(Fragment, { children: [
      /* @__PURE__ */ jsx(
        Accordion,
        {
          startOpen: isOpen,
          showText: header,
          hideText: header,
          onChange: (isOpen2) => handleAccordionChange(id, isOpen2),
          children: details
        }
      ),
      index < content.length - 1 && /* @__PURE__ */ jsx(Divider, {})
    ] }, id);
  }) });
};
AccordionList.displayName = "AccordionList";

export {
  AccordionList
};
//# sourceMappingURL=chunk-EJLNC5X5.js.map
