import { jsxs as f, jsx as o } from "@emotion/react/jsx-runtime";
import { TEST_PROP_ID as A } from "../../../../test/constants_no_mock.js";
import { getNameDataTestId as D } from "../../../../test/getNameDataTestId.js";
import { ACCORDION_KEY as u } from "./constants.js";
import { getComponentSlotRoot as T } from "../../../../utils/getComponentSlotRoot.js";
import { AccordionRootStyled as b, AccordionSummaryStyled as N, IconLabelStyled as R, LabelStyled as v, IconExpandedStyled as O, AccordionDetailsStyled as w } from "./slots/AccordionSlots.js";
import { forwardRef as P, useState as _, useEffect as k } from "react";
import { useComponentSize as L } from "../../../../hooks/useComponentSize/index.js";
import j from "clsx";
import { ArrowChevronMdDownOutlined as W } from "@m4l/icons";
function K(r) {
  return r.replace(/\\r\\n/g, `
`).replace(/\\n/g, `
`).replace(/\\t/g, "	").replace(/\r\n/g, `
`).replace(/\r/g, `
`);
}
const U = P((r, x) => {
  const {
    label: S,
    children: a,
    accordionProps: d,
    summaryProps: g,
    icon: i,
    className: h,
    dataTestId: y = "",
    skeletonLabelWidth: C = "100px",
    size: l,
    expanded: t,
    variant: z = "outlined"
  } = r, { currentSize: c } = L(l), E = T(u), [s, p] = _(t ?? d?.defaultExpanded ?? !0), m = typeof a == "string" ? K(a) : null, I = () => {
    p((n) => !n);
  };
  k(() => {
    let n = !0;
    return n && t !== void 0 && p(t), () => {
      n = !1;
    };
  }, [t]);
  const e = {
    size: c,
    variant: z,
    expanded: s,
    hasTextContent: m !== null
  };
  return /* @__PURE__ */ f(
    b,
    {
      ownerState: e,
      ref: x,
      role: "contentinfo",
      className: j(E, h),
      expanded: s,
      ...d,
      ...process.env.NODE_ENV !== "production" ? { [A]: D(u, "root", y) } : {},
      children: [
        /* @__PURE__ */ f(
          N,
          {
            ownerState: e,
            role: "heading",
            "aria-controls": "expanded-content",
            onClick: I,
            expandIcon: /* @__PURE__ */ o(
              O,
              {
                ownerState: e,
                size: c,
                "aria-label": "settings",
                src: /* @__PURE__ */ o(W, {})
              }
            ),
            ...g,
            children: [
              i && /* @__PURE__ */ o(R, { ownerState: e, src: i, size: l }),
              /* @__PURE__ */ o(
                v,
                {
                  ownerState: e,
                  size: c,
                  variant: "captionDens",
                  skeletonWidth: C,
                  children: S
                }
              )
            ]
          }
        ),
        /* @__PURE__ */ o(w, { ownerState: e, children: m ?? a })
      ]
    }
  );
});
export {
  U as Accordion
};
