import { jsxs as g, jsx as j } from "react/jsx-runtime";
import { useCallback as p, useMemo as B, useState as E, useRef as F, useEffect as T } from "react";
import { B as H } from "../button/button.js";
import { c as I, s as K, m as O, a as R } from "../tools/tools.js";
import { A as q } from "./alert-heading.js";
import { A as D } from "./alert-link.js";
const M = {
  clickToClose: !0
}, U = (C) => {
  const { clickToClose: a, dismissible: m, fade: t, onVisibleChange: s, visible: e } = C, [i, l] = E(!t && typeof e == "boolean" ? e : !0), [r, o] = E(!1), d = F(null), f = p(() => {
    t ? o(!1) : l(!1);
  }, [t]), u = p(() => {
    typeof e == "boolean" && m || a && f(), s == null || s(!e);
  }, [a, m, f, s, e]);
  return T(() => {
    typeof e == "boolean" ? t ? e ? l(!0) : o(!1) : l(e) : t && o(!0);
  }, [t, e]), T(() => {
    if (!t)
      return;
    const n = d.current;
    if (n) {
      const b = () => {
        typeof e == "boolean" ? e || l(!1) : !r && i && l(!1);
      };
      return n.addEventListener("transitionend", b), typeof e == "boolean" && e && requestAnimationFrame(() => {
        o(!0);
      }), () => n.removeEventListener("transitionend", b);
    }
  }, [t, e, i, r]), { alertElement: d, handleClose: u, isShowing: r, isVisible: i };
}, A = function(a) {
  const {
    as: m = "div",
    className: t,
    clickToClose: s = M.clickToClose,
    closeButton: e,
    closeButtonProps: i,
    dismissible: l,
    dropOldClass: r,
    fade: o,
    onVisibleChange: d,
    style: f,
    variables: u,
    variant: n,
    visible: b,
    ...L
  } = a, { alertElement: S, handleClose: k, isShowing: v, isVisible: x } = U({
    clickToClose: s,
    dismissible: l,
    fade: o,
    onVisibleChange: d,
    visible: b
  }), h = p(
    (c) => {
      var y;
      k(), (y = i == null ? void 0 : i.onClick) == null || y.call(i, c);
    },
    [i, k]
  ), w = B(() => {
    const c = I(
      !r && "alert",
      n && `alert-${n}`,
      l && "alert-dismissible",
      o && "fade",
      v && "show",
      t
    ), y = K((V, N) => ({ tKey: R(N) }), u, f);
    return {
      className: c,
      style: y
    };
  }, [t, l, r, o, v, f, u, n]);
  return x && /* @__PURE__ */ g(m, { ...L, ...w, ref: S, children: [
    a.children,
    l && (e || /* @__PURE__ */ j(
      H,
      {
        btnClose: !0,
        ...O(i, {
          onClick: (c) => h(c)
        })
      }
    ))
  ] });
};
A.Link = D;
A.Heading = q;
A.displayName = "BRL.Alert";
export {
  A
};
//# sourceMappingURL=alert.js.map
