import { jsx as B } from "react/jsx-runtime";
import { useState as b, useRef as C, useMemo as L, useCallback as E, useEffect as S } from "react";
import { c as N, s as A, a as F, w as K } from "../tools/tools.js";
const P = function(h) {
  const {
    as: k = "div",
    backdrop: f,
    className: d,
    dropOldClass: m,
    fade: t = !0,
    onChange: n,
    scroll: i,
    style: u,
    variables: p,
    visible: e = !1,
    ...w
  } = h, [l, c] = b(e), [v, r] = b(!1), y = C(null), O = L(() => {
    const s = N(!m && "offcanvas-backdrop", t && "fade", v && "show", d), a = A((o, x) => ({ tKey: F(x) }), p, u);
    return {
      className: s,
      style: a
    };
  }, [d, m, t, v, u, p]), g = E(
    (s) => {
      f !== "static" && (r(!1), n == null || n(!1, s));
    },
    [f, n]
  );
  return S(() => {
    if (!t) {
      c(e), r(e);
      return;
    }
    if (e && !l) {
      c(!0);
      return;
    }
    const s = y.current;
    if (!s)
      return;
    const a = () => {
      e || (i || (document.body.classList.remove("overflow-hidden"), document.body.style.removeProperty("padding-right")), c(!1));
    };
    s.addEventListener("transitionend", a);
    let o;
    return e ? (i || (document.body.style.setProperty("padding-right", K("px")), document.body.classList.add("overflow-hidden")), o = requestAnimationFrame(() => r(!0))) : r(!1), () => {
      s.removeEventListener("transitionend", a), o && cancelAnimationFrame(o);
    };
  }, [t, i, l, e]), l && /* @__PURE__ */ B(k, { ...w, ...O, onClick: g, ref: y });
};
P.displayName = "BRL.OffcanvasBackdrop";
export {
  P as O
};
//# sourceMappingURL=offcanvas-backdrop.js.map
