import h from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import M from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import W from "../../@rc-component/portal/es/Portal.mjs";
import $ from "../../rc-util/es/hooks/useLayoutEffect.mjs";
import * as o from "react";
import { RefContext as X } from "./context.mjs";
import Y from "./DrawerPopup.mjs";
import { warnCheck as Z } from "./util.mjs";
var ee = function(e) {
  var s = e.open, g = s === void 0 ? !1 : s, f = e.prefixCls, D = f === void 0 ? "rc-drawer" : f, c = e.placement, b = c === void 0 ? "right" : c, d = e.autoFocus, S = d === void 0 ? !0 : d, m = e.keyboard, K = m === void 0 ? !0 : m, v = e.width, x = v === void 0 ? 378 : v, p = e.mask, C = p === void 0 ? !0 : p, k = e.maskClosable, L = k === void 0 ? !0 : k, y = e.getContainer, _ = e.forceRender, n = e.afterOpenChange, N = e.destroyOnClose, P = e.onMouseEnter, F = e.onMouseOver, A = e.onMouseLeave, U = e.onClick, V = e.onKeyDown, j = e.onKeyUp, w = e.panelRef, H = o.useState(!1), R = M(H, 2), a = R[0], T = R[1];
  process.env.NODE_ENV !== "production" && Z(e);
  var q = o.useState(!1), O = M(q, 2), z = O[0], B = O[1];
  $(function() {
    B(!0);
  }, []);
  var t = z ? g : !1, E = o.useRef(), r = o.useRef();
  $(function() {
    t && (r.current = document.activeElement);
  }, [t]);
  var G = function(u) {
    var i;
    if (T(u), n == null || n(u), !u && r.current && !((i = E.current) !== null && i !== void 0 && i.contains(r.current))) {
      var l;
      (l = r.current) === null || l === void 0 || l.focus({
        preventScroll: !0
      });
    }
  }, I = o.useMemo(function() {
    return {
      panel: w
    };
  }, [w]);
  if (!_ && !a && !t && N)
    return null;
  var J = {
    onMouseEnter: P,
    onMouseOver: F,
    onMouseLeave: A,
    onClick: U,
    onKeyDown: V,
    onKeyUp: j
  }, Q = h(h({}, e), {}, {
    open: t,
    prefixCls: D,
    placement: b,
    autoFocus: S,
    keyboard: K,
    width: x,
    mask: C,
    maskClosable: L,
    inline: y === !1,
    afterOpenChange: G,
    ref: E
  }, J);
  return /* @__PURE__ */ o.createElement(X.Provider, {
    value: I
  }, /* @__PURE__ */ o.createElement(W, {
    open: t || _ || a,
    autoDestroy: !1,
    getContainer: y,
    autoLock: C && (t || a)
  }, /* @__PURE__ */ o.createElement(Y, Q)));
};
process.env.NODE_ENV !== "production" && (ee.displayName = "Drawer");
export {
  ee as default
};
