import{r as b,N as te,bX as L,aN as W,c4 as D,f as n,bN as _,ak as ne,ah as ae,V as S,c5 as re,_ as oe,ai as ie}from"./main-BzPVmAp-.js";var le=L.ESC,se=L.TAB;function ce(e){var f=e.visible,r=e.triggerRef,s=e.onVisibleChange,u=e.autoFocus,o=e.overlayRef,a=b.useRef(!1),c=function(){if(f){var t,i;(t=r.current)===null||t===void 0||(i=t.focus)===null||i===void 0||i.call(t),s==null||s(!1)}},h=function(){var t;return(t=o.current)!==null&&t!==void 0&&t.focus?(o.current.focus(),a.current=!0,!0):!1},p=function(t){switch(t.keyCode){case le:c();break;case se:{var i=!1;a.current||(i=h()),i?t.preventDefault():c();break}}};b.useEffect(function(){return f?(window.addEventListener("keydown",p),u&&te(h,3),function(){window.removeEventListener("keydown",p),a.current=!1}):function(){a.current=!1}},[f])}var fe=b.forwardRef(function(e,f){var r=e.overlay,s=e.arrow,u=e.prefixCls,o=b.useMemo(function(){var c;return typeof r=="function"?c=r():c=r,c},[r]),a=W(f,D(o));return n.createElement(n.Fragment,null,s&&n.createElement("div",{className:"".concat(u,"-arrow")}),n.cloneElement(o,{ref:_(o)?a:void 0}))}),v={adjustX:1,adjustY:1},d=[0,0],ue={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,f){var r,s=e.arrow,u=s===void 0?!1:s,o=e.prefixCls,a=o===void 0?"rc-dropdown":o,c=e.transitionName,h=e.animation,p=e.align,g=e.placement,t=g===void 0?"bottomLeft":g,i=e.placements,j=i===void 0?ue:i,$=e.getPopupContainer,K=e.showAction,B=e.hideAction,H=e.overlayClassName,X=e.overlayStyle,I=e.visible,O=e.trigger,A=O===void 0?["hover"]:O,Y=e.autoFocus,M=e.overlay,y=e.children,w=e.onVisibleChange,q=ne(e,ve),z=n.useState(),E=ae(z,2),G=E[0],x=E[1],R="visible"in e?I:G,P=n.useRef(null),V=n.useRef(null),k=n.useRef(null);n.useImperativeHandle(f,function(){return P.current});var T=function(l){x(l),w==null||w(l)};ce({visible:R,triggerRef:k,onVisibleChange:T,autoFocus:Y,overlayRef:V});var J=function(l){var C=e.onOverlayClick;x(!1),C&&C(l)},F=function(){return n.createElement(fe,{ref:V,overlay:M,prefixCls:a,arrow:u})},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(k,D(y)):void 0}),N=B;return!N&&A.indexOf("contextMenu")!==-1&&(N=["click"]),n.createElement(re,oe({builtinPlacements:j},q,{prefixCls:a,ref:P,popupClassName:S(H,ie({},"".concat(a,"-show-arrow"),u)),popupStyle:X,action:A,showAction:K,hideAction:N,popupPlacement:t,popupAlign:p,popupTransitionName:c,popupAnimation:h,popupVisible:R,stretch:U()?"minWidth":"",popup:Q(),onPopupVisibleChange:T,onPopupClick:J,getPopupContainer:$}),ee)}const me=n.forwardRef(de);export{me as D};
