import { j as e } from "../../_virtual/jsx-runtime.js";
import { useState as l, useEffect as h } from "react";
import { AccordionWrapper as c, CollapsableContainer as x, AccordionHeader as u, AccordionHeaderPrimaryRow as m, AccordionHeaderTitle as C, AccordionChevron as j, AccordionHeaderSecondaryRow as f, AccordionContent as v } from "./styles.js";
import { getId as b } from "../../utils/index.js";
function g(t) {
  const { isCollapsed: i = !0 } = t, [d, n] = l(i), a = b(t["data-testid"]);
  function r(s) {
    s.preventDefault();
    const o = !d;
    n(o), t.variant !== "custom" && t.onToggle && t.onToggle(o);
  }
  switch (h(() => {
    n(!!i);
  }, [i]), t.variant) {
    case "default":
    case "low-emphasis":
      return /* @__PURE__ */ e.jsxs(
        c,
        {
          hasDivider: t.divider,
          "data-testid": t["data-testid"],
          "data-trackid": t["data-trackid"],
          children: [
            /* @__PURE__ */ e.jsxs(
              u,
              {
                type: "button",
                id: "accordion-button",
                disabled: t.disableCollapse,
                isCollapsed: d,
                onClick: r,
                "data-testid": a("header"),
                "aria-controls": "accordion-content",
                "aria-expanded": !d,
                children: [
                  /* @__PURE__ */ e.jsxs(m, { children: [
                    /* @__PURE__ */ e.jsxs(
                      C,
                      {
                        variant: t.variant,
                        "data-testid": a("title-wrapper"),
                        children: [
                          t.icon && /* @__PURE__ */ e.jsx("span", { "data-testid": a("title-icon"), children: t.icon }),
                          /* @__PURE__ */ e.jsx("span", { "data-testid": a("title-text"), children: t.primaryText })
                        ]
                      }
                    ),
                    !t.hideChevron && /* @__PURE__ */ e.jsx(
                      j,
                      {
                        "data-testid": a("header-chevron")
                      }
                    )
                  ] }),
                  t.secondaryText && /* @__PURE__ */ e.jsx(
                    f,
                    {
                      "data-testid": a("secondary-row"),
                      children: t.secondaryText
                    }
                  )
                ]
              }
            ),
            /* @__PURE__ */ e.jsx(
              v,
              {
                id: "accordion-content",
                role: "region",
                "aria-labelledby": "accordion-button",
                isCollapsed: d,
                "data-testid": a("content"),
                "aria-hidden": d,
                children: t.children
              }
            )
          ]
        }
      );
    case "custom":
      return /* @__PURE__ */ e.jsxs(c, { "data-testid": t["data-testid"], children: [
        t.header,
        /* @__PURE__ */ e.jsx(
          x,
          {
            isCollapsed: d,
            "data-testid": a("content"),
            "aria-hidden": d,
            children: t.content
          }
        )
      ] });
    default:
      throw new Error("Incorrect variant");
  }
}
export {
  g as Accordion
};
