import re from "../../../../@babel/runtime/helpers/esm/extends.mjs";
import h from "../../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import ae from "../../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import le from "../../../../classnames/index.mjs";
import fe from "../../../../rc-motion/es/CSSMotion.mjs";
import "../../../../rc-motion/es/CSSMotionList.mjs";
import * as o from "react";
import me from "../../../../rc-resize-observer/es/index.mjs";
import se from "../../../../rc-util/es/hooks/useLayoutEffect.mjs";
import { composeRef as ce } from "../../../../rc-util/es/ref.mjs";
import ue from "./Arrow.mjs";
import de from "./Mask.mjs";
import ve from "./PopupContent.mjs";
var he = /* @__PURE__ */ o.forwardRef(function(e, A) {
  var g = e.popup, V = e.className, s = e.prefixCls, D = e.style, C = e.target, L = e.onVisibleChanged, n = e.open, _ = e.keepDom, I = e.fresh, H = e.onClick, O = e.mask, x = e.arrow, y = e.arrowPos, c = e.align, l = e.motion, W = e.maskMotion, N = e.forceRender, i = e.getPopupContainer, $ = e.autoDestroy, B = e.portal, R = e.zIndex, T = e.onMouseEnter, X = e.onMouseLeave, Y = e.onPointerEnter, j = e.ready, U = e.offsetX, q = e.offsetY, F = e.offsetR, G = e.offsetB, J = e.onAlign, k = e.onPrepare, f = e.stretch, u = e.targetWidth, d = e.targetHeight, K = typeof g == "function" ? g() : g, Q = n || _, E = (i == null ? void 0 : i.length) > 0, Z = o.useState(!i || !E), S = ae(Z, 2), P = S[0], p = S[1];
  if (se(function() {
    !P && E && C && p(!0);
  }, [P, E, C]), !P)
    return null;
  var r = "auto", t = {
    left: "-1000vw",
    top: "-1000vh",
    right: r,
    bottom: r
  };
  if (j || !n) {
    var b, M = c.points, z = c.dynamicInset || ((b = c._experimental) === null || b === void 0 ? void 0 : b.dynamicInset), ee = z && M[0][1] === "r", te = z && M[0][0] === "b";
    ee ? (t.right = F, t.left = r) : (t.left = U, t.right = r), te ? (t.bottom = G, t.top = r) : (t.top = q, t.bottom = r);
  }
  var a = {};
  return f && (f.includes("height") && d ? a.height = d : f.includes("minHeight") && d && (a.minHeight = d), f.includes("width") && u ? a.width = u : f.includes("minWidth") && u && (a.minWidth = u)), n || (a.pointerEvents = "none"), /* @__PURE__ */ o.createElement(B, {
    open: N || Q,
    getContainer: i && function() {
      return i(C);
    },
    autoDestroy: $
  }, /* @__PURE__ */ o.createElement(de, {
    prefixCls: s,
    open: n,
    zIndex: R,
    mask: O,
    motion: W
  }), /* @__PURE__ */ o.createElement(me, {
    onResize: J,
    disabled: !n
  }, function(oe) {
    return /* @__PURE__ */ o.createElement(fe, re({
      motionAppear: !0,
      motionEnter: !0,
      motionLeave: !0,
      removeOnLeave: !1,
      forceRender: N,
      leavedClassName: "".concat(s, "-hidden")
    }, l, {
      onAppearPrepare: k,
      onEnterPrepare: k,
      visible: n,
      onVisibleChanged: function(v) {
        var m;
        l == null || (m = l.onVisibleChanged) === null || m === void 0 || m.call(l, v), L(v);
      }
    }), function(w, v) {
      var m = w.className, ne = w.style, ie = le(s, m, V);
      return /* @__PURE__ */ o.createElement("div", {
        ref: ce(oe, A, v),
        className: ie,
        style: h(h(h(h({
          "--arrow-x": "".concat(y.x || 0, "px"),
          "--arrow-y": "".concat(y.y || 0, "px")
        }, t), a), ne), {}, {
          boxSizing: "border-box",
          zIndex: R
        }, D),
        onMouseEnter: T,
        onMouseLeave: X,
        onPointerEnter: Y,
        onClick: H
      }, x && /* @__PURE__ */ o.createElement(ue, {
        prefixCls: s,
        arrow: x,
        arrowPos: y,
        align: c
      }), /* @__PURE__ */ o.createElement(ve, {
        cache: !n && !I
      }, K));
    });
  }));
});
process.env.NODE_ENV !== "production" && (he.displayName = "Popup");
export {
  he as default
};
