import { jsx as B } from "react/jsx-runtime";
import { useMemo as S, useState as m, useRef as w, useEffect as b } from "react";
import { c as K, s as O, a as R } from "../tools/tools.js";
const T = (h, l, e) => {
  const [t, y] = m(h), [a, d] = m(!1), [i, H] = m(!1), [v, u] = m(!1), [g, c] = m(0), E = w(null), f = w(null);
  return b(() => {
    y(h);
  }, [h]), b(() => {
    if (!l) {
      e == null || e(t);
      return;
    }
    const s = E.current, o = f.current;
    if (s && o) {
      const n = () => {
        u(!1), H(!0), d(t), e == null || e(t);
      }, r = o.offsetHeight + "", p = o.dataset.lastHeight;
      return (!p || r !== "0" && p !== r) && (o.dataset.lastHeight = r), s.addEventListener("transitionend", n), H(!1), () => s.removeEventListener("transitionend", n);
    }
  }, [t, l, e]), b(() => {
    l && (i || d(!1));
  }, [i, l]), b(() => {
    if (l && !i && !a) {
      const s = f.current;
      if (s) {
        const o = s.offsetHeight, n = s.dataset.lastHeight, r = t ? n ? Number(n) : o : 0;
        c(r), u(!0);
      }
    }
  }, [i, a, t, l]), {
    bodyElement: f,
    collapse: i,
    collapseElement: E,
    collapseHeight: g,
    collapsing: v,
    show: t,
    visible: a
  };
}, V = function(l) {
  const {
    as: e = "div",
    children: t,
    className: y,
    collapsing: a = !0,
    dropOldClass: d,
    onChange: i,
    show: H = !0,
    style: v,
    variables: u,
    ...g
  } = l, c = a === void 0 || a, { bodyElement: E, collapse: f, collapseElement: s, collapseHeight: o, collapsing: n, show: r, visible: p } = T(
    H,
    c,
    i
  ), A = S(() => {
    const N = K(
      !d && "accordion-collapse",
      n && "collapsing",
      c && f && "collapse",
      c && p && "show",
      !c && (r ? "collapse show" : "collapse"),
      y
    ), x = O(
      (j, L) => ({ tKey: R(L) }),
      {
        height: c && o
      },
      u,
      v
    );
    return {
      className: N,
      style: x
    };
  }, [y, f, o, n, d, c, r, v, u, p]);
  return /* @__PURE__ */ B(e, { ...g, ...A, ref: s, children: /* @__PURE__ */ B("div", { className: "accordion-body", ref: E, children: t }) });
};
V.displayName = "BRL.AccordionBody";
export {
  V as A
};
//# sourceMappingURL=accordion-body.js.map
