"use strict";const x=require("./tslib.es6-C4EgNkz1.js"),e=require("react"),s=require("classnames"),m=require("./utils-C9NL3q0j.js"),R=require("./index-Bsb1LHpi.js"),W=require("./random-id-DlJj_RWH.js"),P=require("./button-xYFMCdP0.js"),$=require("./icon-I30uh1Ov.js"),A=require("./icon-button-AJ6dtyvc.js"),_=require("./menu-item-B2Tu5ZPj.js"),G=require("./dropdown-B6wMNyjP.js"),J=require("./icons/ebay-icon-overflow-horizontal-24/index.js"),Q=o=>{var{a11yText:r,noToggleIcon:c,fixWidth:M,reverse:b,variant:f,strategy:B,expanded:q=!1,className:w,icon:h,onCollapse:N=()=>{},onExpand:O=()=>{},onMouseDown:F=()=>{},onSelect:S=()=>{},text:p="",children:u}=o,C=x.__rest(o,["a11yText","noToggleIcon","fixWidth","reverse","variant","strategy","expanded","className","icon","onCollapse","onExpand","onMouseDown","onSelect","text","children"]);const[a,l]=e.useState(q),[E,T]=e.useState(),y=h||m.findComponent(u,$.EbayIcon),j=m.findComponent(u,k)||(y?e.createElement("span",null,p):p),D=m.filterByType(u,[g,I]),{overlayStyles:L,refs:i}=G.useFloatingDropdown({open:a,options:{reverse:b,strategy:B}}),d=i.host;e.useEffect(()=>{const t=n=>{d.current&&!d.current.contains(n.currentTarget)&&l(!1)};return a?(O(),setTimeout(()=>{document.addEventListener("click",t,!1)})):a===!1&&N(),()=>document.removeEventListener("click",t,!1)},[a]),e.useEffect(()=>{T(W.randomId())},[]);const H=t=>{R.handleEscapeKeydown(t,()=>{var n;l(!1),(n=d.current)===null||n===void 0||n.focus()})},K=s("fake-menu-button__menu",{"menu-button__menu--fix-width":M,"menu-button__menu--reverse":b}),v=Object.assign({ref:i.setHost,className:"fake-menu-button__button","aria-expanded":!!a,"aria-haspopup":!0,"aria-label":r,"aria-controls":E,onClick:()=>l(!a)},C);return e.createElement("span",{className:s("fake-menu-button",w)},f==="overflow"?e.createElement(A.EbayIconButton,Object.assign({icon:e.createElement(J.EbayIconOverflowHorizontal24,null)},v)):e.createElement(P.EbayButton,Object.assign({variant:f==="form"?"form":void 0,bodyState:c?void 0:"expand"},v),y,j),a&&e.createElement(_.EbayFakeMenu,{ref:i.setOverlay,className:K,id:E,tabIndex:-1,onKeyDown:H,onSelect:S,style:L},D.map((t,n)=>e.cloneElement(t,Object.assign(Object.assign({},t.props),{onMouseDown:z=>{F(z,{index:n})},className:s(t.props.className,"fake-menu-button__item"),key:n,autoFocus:n===0})))))},g=_.EbayMenuItem,I=o=>{var{className:r}=o,c=x.__rest(o,["className"]);return e.createElement("hr",Object.assign({},c,{className:s(r,"menu-button__separator")}))},k=({children:o})=>e.createElement(e.Fragment,null,o);exports.EbayFakeMenuButtonItem=g;exports.EbayFakeMenuButtonLabel=k;exports.EbayMenuButton=Q;exports.EbayMenuButtonSeparator=I;
