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