import { jsx as u, jsxs as T } from "react/jsx-runtime";
import $ from "../../node_modules/.pnpm/@sindresorhus_slugify@2.2.1/node_modules/@sindresorhus/slugify/index.js";
import { useId as h, useContext as j, createContext as C, useState as E, useRef as z, useEffect as G } from "react";
import { Classes as S } from "../../constants/selectors.js";
import { cn as H } from "../../utils/cn.js";
import { AccordionCover as P } from "./accordion-cover.js";
import { CONNECTING_CHARACTER as q } from "./accordion-url-utils.js";
import { Icon as B } from "../icon/icon.js";
const Z = ({
  title: r,
  description: b,
  defaultOpen: c = !1,
  icon: d,
  iconType: i,
  children: x,
  className: g,
  _disabled: y,
  trackOpen: s,
  trackClose: f,
  onMount: n,
  topOffset: a,
  getInitialOpenFromUrl: p,
  onUrlStateChange: I,
  _onKeyDownCapture: e
}) => {
  const o = typeof r == "string" ? r : "";
  return /* @__PURE__ */ u(
    D,
    {
      _disabled: y,
      _onKeyDownCapture: e,
      className: g,
      defaultOpen: c === !0 || typeof c == "string" && c === "true",
      description: b,
      getInitialOpenFromUrl: p,
      icon: typeof d == "string" ? /* @__PURE__ */ u(B, { className: "size-4", icon: d, iconType: i }) : d,
      onChange: (m) => {
        m ? s == null || s({ title: o }) : f == null || f({ title: o });
      },
      onMount: n,
      onUrlStateChange: I,
      title: r,
      topOffset: a,
      children: x
    }
  );
}, N = C({ parentIds: [] }), D = ({
  title: r,
  description: b,
  defaultOpen: c = !1,
  icon: d,
  onChange: i,
  children: x,
  className: g,
  _disabled: y,
  onMount: s,
  topOffset: f,
  getInitialOpenFromUrl: n,
  onUrlStateChange: a,
  _onKeyDownCapture: p
}) => {
  const I = h(), e = typeof r == "string" ? $(r.split(q).join("-"), {
    decamelize: !1
  }) : I, o = j(N), v = n && e && n(e, o.parentIds) === !0 ? !0 : c, [R, m] = E(v), l = z(v);
  G(() => {
    n && e && n(e, o.parentIds) === !0 && !l.current && (m(!0), l.current = !0), s == null || s();
  }, []);
  const w = (t) => {
    m(t), l.current = t, !y && a && a(
      t,
      typeof r == "string" ? e : void 0,
      o.parentIds
    ), i == null || i(t);
  };
  return /* @__PURE__ */ u(
    N.Provider,
    {
      value: {
        ...o,
        parentIds: [
          ...o.parentIds,
          ...typeof r == "string" ? [e] : []
        ]
      },
      children: /* @__PURE__ */ T(
        "details",
        {
          className: H(
            S.Accordion,
            "mb-3 cursor-default overflow-hidden rounded-2xl border border-stone-200/70 bg-white dark:border-white/10 dark:bg-[#0b0c0e]",
            g
          ),
          "data-component-part": "accordion",
          ...p && { onKeyDownCapture: p },
          onToggle: (t) => {
            const A = t.currentTarget.open;
            A !== l.current && w(A);
          },
          open: R,
          children: [
            /* @__PURE__ */ u(
              P,
              {
                description: b,
                icon: d,
                id: e,
                open: R,
                title: r,
                topOffset: f
              }
            ),
            /* @__PURE__ */ u(
              "div",
              {
                "aria-labelledby": `${e}-label`,
                className: "prose prose-stone dark:prose-invert mx-6 mt-2 mb-4 cursor-default overflow-x-auto",
                "data-component-part": "accordion-content",
                id: `${e}-accordion-children`,
                role: "region",
                children: x
              }
            )
          ]
        },
        typeof r == "string" ? r : "accordion"
      )
    }
  );
};
export {
  Z as Accordion
};
