import { jsxs as f, jsx as r } from "react/jsx-runtime";
import { aE as y } from "./use-page-data.BYLN5MSa.js";
import { a as n } from "./twind.Cg2g8xBZ.js";
import { useState as p } from "react";
import { a as g } from "./index.DpxLxIqU.js";
import { T as d } from "./TextContent.i83ueo1A.js";
import { b } from "./use-section-style.CqWLdjop.js";
import { B as I } from "./BrickRoot.CQgjTuOI.js";
function T({ brick: s, editable: o }) {
  const u = b(s), { props: l } = s, a = Array.isArray(l.items) ? l.items : [], { rounding: h, ...x } = u, [w, O] = p(
    a.findIndex((e) => !!e.defaultOpen) || null
  ), [N, v] = p(() => a.map((e) => !!e.defaultOpen));
  return /* @__PURE__ */ f(
    I,
    {
      brick: s,
      editable: o,
      manifest: y,
      className: n("flex flex-col overflow-hidden relative", Object.values(x)),
      children: [
        o && a.length === 0 && /* @__PURE__ */ r("div", { className: "absolute top-0 left-0 right-0 bottom-0 flex items-center justify-center text-center p-8", children: /* @__PURE__ */ r("div", { className: "text-base", children: "Add content to this accordion in the panel" }) }),
        a.map((e, t) => {
          const i = l.restrictOneOpen ? w === t : N[t] || e.defaultOpen;
          return /* @__PURE__ */ f("div", { className: n("flex flex-col border", h, "overflow-hidden"), children: [
            /* @__PURE__ */ f(
              "button",
              {
                type: "button",
                "aria-expanded": i,
                onClick: () => {
                  l.restrictOneOpen ? O((c) => c === t ? null : t) : v((c) => {
                    const m = [...c];
                    return m[t] = !m[t], m;
                  });
                },
                className: n(
                  "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%] ",
                  i && "rounded-b-none border-b"
                ),
                children: [
                  /* @__PURE__ */ r("div", { className: n("flex flex-grow shrink-0 flex-row items-center gap-1"), children: /* @__PURE__ */ r(
                    d,
                    {
                      propPath: `items.${t}.title`,
                      className: n("w-full", o && "cursor-text"),
                      brickId: s.id,
                      content: e.title,
                      rawContent: e.title,
                      editable: o,
                      inline: !0
                    }
                  ) }),
                  /* @__PURE__ */ r(g, { className: n("transition-transform", i && "rotate-90") })
                ]
              }
            ),
            /* @__PURE__ */ r("div", { className: n("transition-all duration-900 ease-in-out p-3 flex-1", !i && "hidden"), children: /* @__PURE__ */ r(
              d,
              {
                propPath: `items.${t}.content`,
                className: n("w-full", o && "cursor-text"),
                brickId: s.id,
                content: e.content,
                rawContent: e.content,
                editable: o
              }
            ) })
          ] }, t);
        })
      ]
    }
  );
}
export {
  T as default
};
