import K from "../../@babel/runtime/helpers/esm/extends.mjs";
import Q from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import U from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import X from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import Y from "../../@rc-component/trigger/es/index.mjs";
import O from "../../classnames/index.mjs";
import { supportRef as Z, composeRef as ee } from "../../rc-util/es/ref.mjs";
import r from "react";
import ie from "./hooks/useAccessibility.mjs";
import re from "./Overlay.mjs";
import ne from "./placements.mjs";
var te = ["arrow", "prefixCls", "transitionName", "animation", "align", "placement", "placements", "getPopupContainer", "showAction", "hideAction", "overlayClassName", "overlayStyle", "visible", "trigger", "autoFocus", "overlay", "children", "onVisibleChange"];
function ae(e, P) {
  var l, u = e.arrow, f = u === void 0 ? !1 : u, g = e.prefixCls, t = g === void 0 ? "rc-dropdown" : g, M = e.transitionName, x = e.animation, V = e.align, v = e.placement, $ = v === void 0 ? "bottomLeft" : v, d = e.placements, T = d === void 0 ? ne : d, E = e.getPopupContainer, S = e.showAction, W = e.hideAction, k = e.overlayClassName, F = e.overlayStyle, L = e.visible, p = e.trigger, h = p === void 0 ? ["hover"] : p, D = e.autoFocus, C = e.overlay, a = e.children, c = e.onVisibleChange, H = X(e, te), j = r.useState(), y = U(j, 2), I = y[0], b = y[1], m = "visible" in e ? L : I, N = r.useRef(null), _ = r.useRef(null), w = r.useRef(null);
  r.useImperativeHandle(P, function() {
    return N.current;
  });
  var R = function(i) {
    b(i), c == null || c(i);
  };
  ie({
    visible: m,
    triggerRef: w,
    onVisibleChange: R,
    autoFocus: D,
    overlayRef: _
  });
  var q = function(i) {
    var o = e.onOverlayClick;
    b(!1), o && o(i);
  }, A = function() {
    return /* @__PURE__ */ r.createElement(re, {
      ref: _,
      overlay: C,
      prefixCls: t,
      arrow: f
    });
  }, z = function() {
    return typeof C == "function" ? A : A();
  }, B = function() {
    var i = e.minOverlayWidthMatchTrigger, o = e.alignPoint;
    return "minOverlayWidthMatchTrigger" in e ? i : !o;
  }, G = function() {
    var i = e.openClassName;
    return i !== void 0 ? i : "".concat(t, "-open");
  }, J = /* @__PURE__ */ r.cloneElement(a, {
    className: O((l = a.props) === null || l === void 0 ? void 0 : l.className, m && G()),
    ref: Z(a) ? ee(w, a.ref) : void 0
  }), s = W;
  return !s && h.indexOf("contextMenu") !== -1 && (s = ["click"]), /* @__PURE__ */ r.createElement(Y, K({
    builtinPlacements: T
  }, H, {
    prefixCls: t,
    ref: N,
    popupClassName: O(k, Q({}, "".concat(t, "-show-arrow"), f)),
    popupStyle: F,
    action: h,
    showAction: S,
    hideAction: s,
    popupPlacement: $,
    popupAlign: V,
    popupTransitionName: M,
    popupAnimation: x,
    popupVisible: m,
    stretch: B() ? "minWidth" : "",
    popup: z(),
    onPopupVisibleChange: R,
    onPopupClick: q,
    getPopupContainer: E
  }), J);
}
const he = /* @__PURE__ */ r.forwardRef(ae);
export {
  he as default
};
