import { j as t } from "../../../../../_virtual/jsx-runtime.js";
import { a as N } from "../../../../sdk/dist/shared/chunk-ZQGNYK5I.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-UU2MSQXY.js";
import "../../../../sdk/dist/shared/chunk-YBGPPF7T.js";
import "../../../../sdk/dist/shared/chunk-UMHXXXVP.js";
import "../../../../sdk/dist/shared/chunk-5N6MBJJ4.js";
import { tx as o } from "../../../../style-system/dist/twind.js";
import { useState as p } from "react";
import { MdKeyboardArrowRight as v } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/md/index.js";
import f from "../components/TextContent.js";
import { useBrickStyle as y } from "../hooks/use-brick-style.js";
import g from "../components/BrickRoot.js";
function T({ brick: n, editable: s }) {
  const d = y(n), { props: l } = n, i = Array.isArray(l.items) ? l.items : [], { rounding: u, ...x } = d, [h, j] = p(
    i.findIndex((e) => !!e.defaultOpen) || null
  ), [w, O] = p(() => i.map((e) => !!e.defaultOpen));
  return /* @__PURE__ */ t.jsxs(
    g,
    {
      brick: n,
      editable: s,
      manifest: N,
      className: o("flex flex-col overflow-hidden relative", Object.values(x)),
      children: [
        s && i.length === 0 && /* @__PURE__ */ t.jsx("div", { className: "absolute top-0 left-0 right-0 bottom-0 flex items-center justify-center text-center p-8", children: /* @__PURE__ */ t.jsx("div", { className: "text-base", children: "Add content to this accordion in the panel" }) }),
        i.map((e, r) => {
          const a = l.restrictOneOpen ? h === r : w[r] || e.defaultOpen;
          return /* @__PURE__ */ t.jsxs("div", { className: o("flex flex-col border", u, "overflow-hidden"), children: [
            /* @__PURE__ */ t.jsxs(
              "button",
              {
                type: "button",
                "aria-expanded": a,
                onClick: () => {
                  l.restrictOneOpen ? j((c) => c === r ? null : r) : O((c) => {
                    const m = [...c];
                    return m[r] = !m[r], m;
                  });
                },
                className: o(
                  "flex flex-grow shrink-0 items-center p-3 gap-1 justify-between w-full",
                  "font-semibold cursor-pointer select-none text-left text-[110%] ",
                  a && "rounded-b-none border-b"
                ),
                children: [
                  /* @__PURE__ */ t.jsx("div", { className: o("flex flex-grow shrink-0 flex-row items-center gap-1"), children: /* @__PURE__ */ t.jsx(
                    f,
                    {
                      propPath: `items.${r}.title`,
                      className: o("w-full", s && "cursor-text"),
                      brickId: n.id,
                      content: e.title,
                      rawContent: e.title,
                      editable: s,
                      inline: !0
                    }
                  ) }),
                  /* @__PURE__ */ t.jsx(v, { className: o("transition-transform", a && "rotate-90") })
                ]
              }
            ),
            /* @__PURE__ */ t.jsx("div", { className: o("transition-all duration-900 ease-in-out p-3 flex-1", !a && "hidden"), children: /* @__PURE__ */ t.jsx(
              f,
              {
                propPath: `items.${r}.content`,
                className: o("w-full", s && "cursor-text"),
                brickId: n.id,
                content: e.content,
                rawContent: e.content,
                editable: s
              }
            ) })
          ] }, r);
        })
      ]
    }
  );
}
export {
  T as default
};
//# sourceMappingURL=accordion.js.map
