import { jsxs as m, jsx as e } from "react/jsx-runtime";
import { Collapsible as K, CollapsibleTrigger as M, CollapsibleContent as R } from "./CollapsiblePrimitive.js";
import { useState as S, useMemo as c, Fragment as $, useCallback as q } from "react";
import v from "../text/Text.js";
import B from "../button/Button.js";
import E from "../icon/Icon.js";
import { c as o } from "../../index-BtlgVD4m.js";
import N from "../box/Box.js";
const G = ({
  title: d,
  triggerContent: f,
  content: C,
  defaultOpen: x = !1,
  showIcon: w = !1,
  togglePosition: P,
  showDivider: O = !1,
  contentBackground: j,
  headerSlot: i,
  secondaryText: r,
  actionButtons: t,
  actionIcon: s,
  actionIconAriaLabel: u,
  onActionIconClick: a,
  showBorder: y = !1,
  ...z
}) => {
  const [b, k] = S(x), n = c(() => d ?? f, [d, f]), g = c(() => {
    if (i)
      return i;
    if (!(!r && !t && !s))
      return /* @__PURE__ */ m($, { children: [
        r != null && (typeof r == "string" ? /* @__PURE__ */ e(v, { color: "muted", children: r }) : r),
        t,
        s && /* @__PURE__ */ e(
          B,
          {
            variant: "ghost",
            size: "xs",
            icon: s,
            "aria-label": u ?? "Collapsible action",
            onClick: (l) => {
              l.stopPropagation(), a == null || a(l);
            }
          }
        )
      ] });
  }, [t, s, u, i, a, r]), p = P ?? (w ? "right" : void 0), D = q((l) => {
    l.stopPropagation();
  }, []), h = /* @__PURE__ */ e(E, { name: "ChevronRight", size: 16, className: o("shrink-0 transition-transform duration-200", b && "rotate-90"), "aria-hidden": "true" }), { className: F, ...H } = z;
  return /* @__PURE__ */ m(
    K,
    {
      ...H,
      open: b,
      onOpenChange: k,
      className: o("rounded-[var(--border-radius-lg)]", y && "border border-[var(--base-border)]", F),
      children: [
        /* @__PURE__ */ e(M, { asChild: !0, className: "hover:cursor-pointer w-full", children: /* @__PURE__ */ m(
          "div",
          {
            tabIndex: 0,
            role: "button",
            className: o(
              "w-full inline-flex flex-row items-center gap-[var(--spacing-2)] p-[var(--spacing-3)]",
              O && "border-b border-[var(--base-border)]"
            ),
            children: [
              p === "left" && h,
              /* @__PURE__ */ e(N, { className: "shrink-0", children: typeof n == "string" ? /* @__PURE__ */ e(v, { type: "body", weight: "medium", color: "default", children: n }) : n }),
              g != null && /* @__PURE__ */ e("div", { className: "flex-1 inline-flex items-center", onClick: D, onKeyDown: (l) => l.stopPropagation(), children: g }),
              p === "right" && /* @__PURE__ */ e("span", { className: "ml-auto", children: h })
            ]
          }
        ) }),
        /* @__PURE__ */ e(R, { children: /* @__PURE__ */ e(
          N,
          {
            className: o(
              "p-[var(--spacing-3)]",
              "rounded-b-[var(--border-radius-lg)]",
              p === "left" && "pl-[var(--spacing-9)]",
              j === "muted" && "bg-[var(--base-muted)]"
            ),
            children: C
          }
        ) })
      ]
    }
  );
};
G.displayName = "Collapsible";
export {
  G as default
};
//# sourceMappingURL=Collapsible.js.map
