import { jsx as e, Fragment as R, jsxs as p } from "react/jsx-runtime";
import { useState as r, useRef as me, useMemo as ue, useCallback as y, useEffect as b } from "react";
import { createPortal as V } from "react-dom";
import { c as Me, s as pe, a as ye } from "../tools/tools.js";
import { M as z } from "./modal-backdrop.js";
import { M as I } from "./modal-body.js";
import { M as W } from "./modal-content.js";
import { M as _ } from "./modal-dialog.js";
import { M as G } from "./modal-footer.js";
import { M as h } from "./modal-header.js";
import { M as v } from "./modal-title.js";
const t = function(J) {
  const {
    as: Q = "div",
    backdropProps: U,
    body: B,
    bodyProps: X,
    centered: Y,
    className: C,
    container: o,
    contentProps: Z,
    dialogProps: $,
    dropOldClass: k,
    fade: M = !0,
    footer: E,
    footerProps: ee,
    fullscreen: oe,
    header: g,
    headerProps: P,
    onVisibleChange: l,
    scrollable: te,
    size: se,
    static: i,
    style: S,
    title: c,
    titleProps: x,
    toggle: re,
    variables: D,
    visible: a = !1,
    ...ne
  } = J, [d, F] = r(!1), [L, T] = r(!1), [w, N] = r(!1), [f, j] = r(a), [ae, q] = r(a), [A, H] = r(!1), [n, K] = r(
    typeof o != "string" ? o : null
  ), O = me(null), le = ue(() => {
    const s = Me(
      !k && "modal",
      M && !n && "fade",
      L && "show",
      d && "d-block",
      w && "modal-static",
      C
    ), m = pe((u, fe) => ({ tKey: ye(fe) }), D, S);
    return {
      className: s,
      style: m
    };
  }, [d, C, n, k, M, w, L, S, D]), ie = y(() => {
    if (!A) {
      if (i) {
        N(!0);
        return;
      }
      j(!1), q(!1), l == null || l(!1);
    }
  }, [A, l, i]), ce = y(() => {
    H(!0);
  }, []), de = y(() => {
    H(!1);
  }, []);
  return b(() => {
    if (f && !d) {
      F(!0);
      return;
    }
    const s = O.current;
    if (!s)
      return;
    const m = () => {
      f || F(!1), i && N(!1);
    };
    s.addEventListener("transitionend", m);
    let u;
    return f ? u = requestAnimationFrame(() => T(!0)) : T(!1), () => {
      s.removeEventListener("transitionend", m), u && cancelAnimationFrame(u);
    };
  }, [d, i, f]), b(() => {
    j(a), q(a);
  }, [a]), b(() => {
    if (typeof o == "string") {
      const s = o.startsWith("#") ? document.getElementById(o.slice(1)) : document.querySelector(o);
      K(s);
    } else
      K(o);
  }, [o]), /* @__PURE__ */ e(R, { children: document !== void 0 && /* @__PURE__ */ p(R, { children: [
    V(
      /* @__PURE__ */ e(Q, { ...ne, ...le, onClick: ie, ref: O, children: /* @__PURE__ */ e(
        _,
        {
          ...$,
          centered: Y,
          fullscreen: oe,
          scrollable: te,
          size: se,
          children: /* @__PURE__ */ p(
            W,
            {
              ...Z,
              onMouseEnter: ce,
              onMouseLeave: de,
              children: [
                g ? /* @__PURE__ */ p(h, { ...P, children: [
                  c && /* @__PURE__ */ e(v, { ...x, children: c }),
                  g
                ] }) : /* @__PURE__ */ e(h, { ...P, children: c && /* @__PURE__ */ e(v, { ...x, children: c }) }),
                B && /* @__PURE__ */ e(I, { ...X, children: B }),
                E && /* @__PURE__ */ e(G, { ...ee, children: E })
              ]
            }
          )
        }
      ) }),
      n || document.body
    ),
    V(
      /* @__PURE__ */ e(
        z,
        {
          ...U,
          fade: M,
          toggle: re,
          visible: ae
        }
      ),
      n || document.body
    )
  ] }) });
};
t.Dialog = _;
t.Content = W;
t.Header = h;
t.Footer = G;
t.Title = v;
t.Body = I;
t.Backdrop = z;
t.displayName = "BRL.Modal";
export {
  t as M
};
//# sourceMappingURL=modal.js.map
