import { jsx as f, jsxs as K, Fragment as O } from "react/jsx-runtime";
import { useState as x, useRef as P, useMemo as R, useCallback as k, useEffect as B } from "react";
import { c as q, s as M, a as V } from "../tools/tools.js";
import { T as E } from "./toast-body.js";
import { T as _ } from "./toast-container.js";
import { T as S } from "./toast-header.js";
const m = function(F) {
  const {
    as: I = "div",
    autohide: c = !0,
    body: u,
    bodyProps: L,
    className: d,
    customContent: h,
    delay: T = 5e3,
    dropOldClass: p,
    fade: o = !0,
    header: y,
    headerProps: N,
    onChange: r,
    style: v,
    variables: C,
    visible: n = !1,
    ...j
  } = F, [t, a] = x(!1), [b, s] = x(!1), w = P(null), A = R(() => {
    const e = q(
      !p && "toast",
      o && "fade",
      t && "show",
      b && "showing",
      d
    ), i = M((l, H) => ({ tKey: V(H) }), C, v);
    return {
      className: e,
      style: i
    };
  }, [d, p, o, t, b, v, C]), g = k(
    (e) => {
      r == null || r(e);
    },
    [r]
  );
  return B(() => {
    let e;
    return c && t && (e = setTimeout(() => {
      g(!1);
    }, T)), () => {
      e && clearTimeout(e);
    };
  }, [c, T, g, t]), B(() => {
    if (!o) {
      a(n);
      return;
    }
    const e = w.current;
    if (!e)
      return;
    const i = () => {
      n ? s(!1) : (s(!1), a(!1));
    };
    e.addEventListener("transitionend", i);
    let l;
    return n ? (a(!0), s(!0), l = requestAnimationFrame(() => s(!1))) : t && (a(!0), s(!0)), () => {
      e.removeEventListener("transitionend", i), l && cancelAnimationFrame(l);
    };
  }, [o, t, n]), /* @__PURE__ */ f(I, { ...j, ...A, ref: w, children: h || /* @__PURE__ */ K(O, { children: [
    y && /* @__PURE__ */ f(S, { ...N, children: y }),
    u && /* @__PURE__ */ f(E, { ...L, children: u })
  ] }) });
};
m.Header = S;
m.Body = E;
m.Container = _;
m.displayName = "BRL.ToastItem";
export {
  m as T
};
//# sourceMappingURL=toast-item.js.map
