import { jsx, jsxs } from "react/jsx-runtime";
import { forwardRef, useCallback } from "react";
import default_1 from "../../node_modules/@mui/icons-material/ExpandMore.js";
/* empty css                      */
import Accordion$1 from "../../node_modules/@mui/material/Accordion/Accordion.js";
import AccordionSummary from "../../node_modules/@mui/material/AccordionSummary/AccordionSummary.js";
import AccordionDetails from "../../node_modules/@mui/material/AccordionDetails/AccordionDetails.js";
const Accordion = forwardRef(
  ({
    expanded,
    setExpanded,
    isMultiExpanded = false,
    data = [],
    onChange,
    isSingleItem = false,
    singleData,
    disabled = false,
    className = "",
    ...args
  }, ref) => {
    const handleSingleAccordionChange = useCallback(
      (value) => {
        if (onChange) {
          onChange(value);
          return;
        }
        if (setExpanded) {
          setExpanded(value);
        }
      },
      [onChange, setExpanded]
    );
    const handleMultiAccordionChange = useCallback(
      (value) => {
        if (onChange) {
          onChange(value);
          return;
        }
        if (!setExpanded) return;
        if (isMultiExpanded && Array.isArray(expanded)) {
          if (!expanded.includes(value)) {
            setExpanded([...expanded, value]);
          } else {
            setExpanded(expanded.filter((item) => item !== value));
          }
        } else if (expanded === value) {
          setExpanded("");
        } else {
          setExpanded(value);
        }
      },
      [onChange, setExpanded, isMultiExpanded, expanded]
    );
    if (isSingleItem && singleData) {
      return /* @__PURE__ */ jsx(
        "div",
        {
          ref,
          className: `impact_accordion_main_container impact_accordion_main_container_single ${className}`.trim(),
          children: /* @__PURE__ */ jsxs(
            Accordion$1,
            {
              className: "accordion_main_container",
              defaultExpanded: expanded === singleData.value,
              disabled,
              onChange: () => {
                handleSingleAccordionChange(singleData.value);
              },
              ...args,
              children: [
                /* @__PURE__ */ jsx(
                  AccordionSummary,
                  {
                    "aria-controls": `${singleData.value}-content`,
                    className: "accordion_header",
                    expandIcon: /* @__PURE__ */ jsx(default_1, {}),
                    id: `${singleData.value}-header`,
                    children: singleData.header
                  }
                ),
                /* @__PURE__ */ jsx(AccordionDetails, { className: "accordion_body", children: singleData.content })
              ]
            }
          )
        }
      );
    }
    return /* @__PURE__ */ jsx("div", { ref, className: `impact_accordion_main_container ${className}`.trim(), children: data.map((item, index) => {
      const isExpanded = isMultiExpanded ? Array.isArray(expanded) && expanded.includes(item.value) : expanded === item.value;
      return /* @__PURE__ */ jsxs(
        Accordion$1,
        {
          className: "accordion_main_container",
          defaultExpanded: isExpanded,
          disabled: disabled || item.disabled,
          expanded: isExpanded,
          onChange: () => {
            handleMultiAccordionChange(item.value);
          },
          ...args,
          children: [
            /* @__PURE__ */ jsx(
              AccordionSummary,
              {
                "aria-controls": `${item.value}-content`,
                className: "accordion_header",
                expandIcon: /* @__PURE__ */ jsx(default_1, {}),
                id: `${item.value}-header`,
                children: item.header
              }
            ),
            /* @__PURE__ */ jsx(AccordionDetails, { className: "accordion_body", children: item.content })
          ]
        },
        item.value || index
      );
    }) });
  }
);
Accordion.displayName = "Accordion";
export {
  Accordion
};
