import b from "../../../@babel/runtime/helpers/esm/extends.mjs";
import i from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import se from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import R from "../../../classnames/index.mjs";
import $ from "../../../rc-util/es/Dom/contains.mjs";
import le from "../../../rc-util/es/hooks/useId.mjs";
import P from "../../../rc-util/es/KeyCode.mjs";
import me from "../../../rc-util/es/pickAttrs.mjs";
import * as s from "react";
import { useRef as l, useEffect as O } from "react";
import { getMotionName as z } from "../util.mjs";
import ce from "./Content/index.mjs";
import ue from "./Mask.mjs";
import { warning as K } from "../../../rc-util/es/warning.mjs";
function xe(e) {
  var g = e.prefixCls, a = g === void 0 ? "rc-dialog" : g, w = e.zIndex, S = e.visible, o = S === void 0 ? !1 : S, E = e.keyboard, V = E === void 0 ? !0 : E, x = e.focusTriggerAfterClose, U = x === void 0 ? !0 : x, W = e.wrapStyle, j = e.wrapClassName, B = e.wrapProps, f = e.onClose, d = e.afterOpenChange, v = e.afterClose, L = e.transitionName, q = e.animation, A = e.closable, F = A === void 0 ? !0 : A, T = e.mask, _ = T === void 0 ? !0 : T, G = e.maskTransitionName, H = e.maskAnimation, D = e.maskClosable, J = D === void 0 ? !0 : D, Q = e.maskStyle, X = e.maskProps, Y = e.rootClassName, n = e.classNames, r = e.styles;
  process.env.NODE_ENV !== "production" && (["wrapStyle", "bodyStyle", "maskStyle"].forEach(function(t) {
    K(!(t in e), "".concat(t, " is deprecated, please use styles instead."));
  }), "wrapClassName" in e && K(!1, "wrapClassName is deprecated, please use classNames instead."));
  var m = l(), c = l(), C = l(), Z = s.useState(o), I = se(Z, 2), k = I[0], h = I[1], ee = le();
  function te() {
    $(c.current, document.activeElement) || (m.current = document.activeElement);
  }
  function ae() {
    if (!$(c.current, document.activeElement)) {
      var t;
      (t = C.current) === null || t === void 0 || t.focus();
    }
  }
  function oe(t) {
    if (t)
      ae();
    else {
      if (h(!1), _ && m.current && U) {
        try {
          m.current.focus({
            preventScroll: !0
          });
        } catch {
        }
        m.current = null;
      }
      k && (v == null || v());
    }
    d == null || d(t);
  }
  function y(t) {
    f == null || f(t);
  }
  var u = l(!1), p = l(), ne = function() {
    clearTimeout(p.current), u.current = !0;
  }, re = function() {
    p.current = setTimeout(function() {
      u.current = !1;
    });
  }, M = null;
  J && (M = function(N) {
    u.current ? u.current = !1 : c.current === N.target && y(N);
  });
  function ie(t) {
    if (V && t.keyCode === P.ESC) {
      t.stopPropagation(), y(t);
      return;
    }
    o && t.keyCode === P.TAB && C.current.changeActive(!t.shiftKey);
  }
  return O(function() {
    o && (h(!0), te());
  }, [o]), O(function() {
    return function() {
      clearTimeout(p.current);
    };
  }, []), /* @__PURE__ */ s.createElement("div", b({
    className: R("".concat(a, "-root"), Y)
  }, me(e, {
    data: !0
  })), /* @__PURE__ */ s.createElement(ue, {
    prefixCls: a,
    visible: _ && o,
    motionName: z(a, G, H),
    style: i(i({
      zIndex: w
    }, Q), r == null ? void 0 : r.mask),
    maskProps: X,
    className: n == null ? void 0 : n.mask
  }), /* @__PURE__ */ s.createElement("div", b({
    tabIndex: -1,
    onKeyDown: ie,
    className: R("".concat(a, "-wrap"), j, n == null ? void 0 : n.wrapper),
    ref: c,
    onClick: M,
    style: i(i(i({
      zIndex: w
    }, W), r == null ? void 0 : r.wrapper), {}, {
      display: k ? null : "none"
    })
  }, B), /* @__PURE__ */ s.createElement(ce, b({}, e, {
    onMouseDown: ne,
    onMouseUp: re,
    ref: C,
    closable: F,
    ariaId: ee,
    prefixCls: a,
    visible: o && k,
    onClose: y,
    onVisibleChanged: oe,
    motionName: z(a, L, q)
  }))));
}
export {
  xe as default
};
