import{o as te,d as ne,k as ae,m as re}from"./@babel-BJZJ6yB5.js";import{T as oe}from"./@rc-component-BWV3LfjC.js";import{c as S}from"./classnames-3ZYesfuy.js";import{w as ie,K as L,d as W,g as D,s as _}from"./rc-util-uI9ZRjCe.js";import{a as b,R as n}from"./react-CXoDaX02.js";var le=L.ESC,se=L.TAB;function fe(e){var u=e.visible,r=e.triggerRef,s=e.onVisibleChange,c=e.autoFocus,o=e.overlayRef,a=b.useRef(!1),f=function(){if(u){var t,i;(t=r.current)===null||t===void 0||(i=t.focus)===null||i===void 0||i.call(t),s?.(!1)}},p=function(){var t;return(t=o.current)!==null&&t!==void 0&&t.focus?(o.current.focus(),a.current=!0,!0):!1},h=function(t){switch(t.keyCode){case le:f();break;case se:{var i=!1;a.current||(i=p()),i?t.preventDefault():f();break}}};b.useEffect(function(){return u?(window.addEventListener("keydown",h),c&&ie(p,3),function(){window.removeEventListener("keydown",h),a.current=!1}):function(){a.current=!1}},[u])}var ue=b.forwardRef(function(e,u){var r=e.overlay,s=e.arrow,c=e.prefixCls,o=b.useMemo(function(){var f;return typeof r=="function"?f=r():f=r,f},[r]),a=W(u,D(o));return n.createElement(n.Fragment,null,s&&n.createElement("div",{className:"".concat(c,"-arrow")}),n.cloneElement(o,{ref:_(o)?a:void 0}))}),v={adjustX:1,adjustY:1},d=[0,0],ce={topLeft:{points:["bl","tl"],overflow:v,offset:[0,-4],targetOffset:d},top:{points:["bc","tc"],overflow:v,offset:[0,-4],targetOffset:d},topRight:{points:["br","tr"],overflow:v,offset:[0,-4],targetOffset:d},bottomLeft:{points:["tl","bl"],overflow:v,offset:[0,4],targetOffset:d},bottom:{points:["tc","bc"],overflow:v,offset:[0,4],targetOffset:d},bottomRight:{points:["tr","br"],overflow:v,offset:[0,4],targetOffset:d}},ve=["arrow","prefixCls","transitionName","animation","align","placement","placements","getPopupContainer","showAction","hideAction","overlayClassName","overlayStyle","visible","trigger","autoFocus","overlay","children","onVisibleChange"];function de(e,u){var r,s=e.arrow,c=s===void 0?!1:s,o=e.prefixCls,a=o===void 0?"rc-dropdown":o,f=e.transitionName,p=e.animation,h=e.align,m=e.placement,t=m===void 0?"bottomLeft":m,i=e.placements,j=i===void 0?ce:i,K=e.getPopupContainer,$=e.showAction,B=e.hideAction,H=e.overlayClassName,I=e.overlayStyle,X=e.visible,N=e.trigger,A=N===void 0?["hover"]:N,Y=e.autoFocus,M=e.overlay,y=e.children,w=e.onVisibleChange,q=te(e,ve),z=n.useState(),E=ne(z,2),G=E[0],x=E[1],R="visible"in e?X:G,P=n.useRef(null),k=n.useRef(null),T=n.useRef(null);n.useImperativeHandle(u,function(){return P.current});var V=function(l){x(l),w?.(l)};fe({visible:R,triggerRef:T,onVisibleChange:V,autoFocus:Y,overlayRef:k});var J=function(l){var C=e.onOverlayClick;x(!1),C&&C(l)},F=function(){return n.createElement(ue,{ref:k,overlay:M,prefixCls:a,arrow:c})},Q=function(){return typeof M=="function"?F:F()},U=function(){var l=e.minOverlayWidthMatchTrigger,C=e.alignPoint;return"minOverlayWidthMatchTrigger"in e?l:!C},Z=function(){var l=e.openClassName;return l!==void 0?l:"".concat(a,"-open")},ee=n.cloneElement(y,{className:S((r=y.props)===null||r===void 0?void 0:r.className,R&&Z()),ref:_(y)?W(T,D(y)):void 0}),O=B;return!O&&A.indexOf("contextMenu")!==-1&&(O=["click"]),n.createElement(oe,ae({builtinPlacements:j},q,{prefixCls:a,ref:P,popupClassName:S(H,re({},"".concat(a,"-show-arrow"),c)),popupStyle:I,action:A,showAction:$,hideAction:O,popupPlacement:t,popupAlign:h,popupTransitionName:f,popupAnimation:p,popupVisible:R,stretch:U()?"minWidth":"",popup:Q(),onPopupVisibleChange:V,onPopupClick:J,getPopupContainer:K}),ee)}const Ce=n.forwardRef(de);export{Ce as D};
