import { jsx as L } from "react/jsx-runtime";
import { useState as w, useRef as E, useMemo as $, useEffect as x } from "react";
import { c as B, s as D, h as m, a as S } from "../tools/tools.js";
const z = (a, o, r = "", i = !1, e) => {
  if (!i)
    return e ? `${e}${r}` : `0${r}`;
  const c = a.dataset[`last${m(o)}`] || "0", t = o === "width" ? a.offsetWidth : a.offsetHeight || c;
  return t !== "0" && (a.dataset[`last${m(o)}`] = t.toString()), `${t}${r}`;
}, N = function(o) {
  const {
    as: r = "div",
    className: i,
    collapsing: e = !0,
    dropOldClass: c,
    horizontal: t,
    style: p,
    variables: d,
    visible: l,
    ...y
  } = o, [h, v] = w(e ? !1 : l ?? !1), u = E(null), C = $(() => {
    const s = B(
      !c && "collapse",
      t && "collapse-horizontal",
      h && "show",
      i
    ), n = D((f, g) => ({ tKey: S(g) }), d, p);
    return { className: s, style: n };
  }, [i, c, t, h, p, d]);
  return x(() => {
    if (!e) {
      v(l ?? !1);
      return;
    }
    const s = u.current;
    if (!s)
      return;
    const n = s.children[0];
    if (!n || !n.dataset[t ? "lastWidth" : "lastHeight"] && !l)
      return;
    const f = () => {
      l ? s.classList.add("collapse", "show") : s.classList.add("collapse"), s.classList.remove("collapsing");
    };
    return s.addEventListener("transitionend", f), s.classList.remove("collapse", "show"), s.classList.add("collapsing"), s.style.setProperty(
      t ? "width" : "height",
      z(n, t ? "width" : "height", "px", l)
    ), () => s.removeEventListener("transitionend", f);
  }, [e, t, l]), /* @__PURE__ */ L(r, { ...y, ...C, ref: u });
};
N.displayName = "BRL.Collapse";
export {
  N as C
};
//# sourceMappingURL=collapse.js.map
