import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{c as n,l as r,t as i}from"./emotion-styled.browser.esm.DmHEQgFq.js";import{c as a}from"./utils.paqmDQdB.js";import{b as o,r as s,v as c,x as l}from"./StreamlitMarkdown.CwaSe4JX.js";import{t as u}from"./useEmotionTheme.tyjAwN1A.js";import{n as d,t as f}from"./styled-components.BnwjjA8j.js";import{t as p}from"./BaseButton.VZZipqV4.js";import{r as m,t as h}from"./useFloatingOverlay.DKo8T0mQ.js";import{C as g,_n as _,bn as v,dn as y,rn as b,tn as x,un as S,vn as C}from"./index.BfkDCGNp.js";var w=e(t(),1),T=i(`div`,{target:`ealm2e00`})(({theme:e,$hideChevron:t})=>({display:`flex`,alignItems:`center`,gap:e.spacing.threeXS,marginRight:t?0:`calc(-${e.iconSizes.lg} * 0.25)`})),E=i(`div`,{target:`ealm2e01`})(({theme:e})=>({display:`inline-flex`,marginTop:e.spacing.threeXS})),D=i(`div`,{target:`ealm2e02`})(({theme:e})=>({display:`flex`,alignItems:`center`,gap:e.spacing.sm,whiteSpace:`nowrap`})),O=i(`span`,{target:`ealm2e03`})(({theme:e})=>({display:`inline-flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,width:e.iconSizes.md,color:e.colors.bodyText})),k=i(`div`,{target:`ealm2e04`})(({theme:e})=>({...l(e),borderRadius:e.radii.xl,maxHeight:`70vh`,overflow:`auto`,zIndex:o(e)})),A=i(y,{target:`ealm2e05`})(({theme:e})=>({backgroundColor:e.colors.bgColor,paddingTop:e.spacing.threeXS,paddingBottom:e.spacing.threeXS,paddingLeft:e.spacing.xs,paddingRight:e.spacing.xs,outline:`none`,boxShadow:`none`,margin:0,minWidth:`100%`})),j=i(S,{target:`ealm2e06`})(({theme:e})=>({display:`flex`,alignItems:`center`,marginTop:e.spacing.twoXS,marginBottom:e.spacing.twoXS,paddingLeft:e.spacing.sm,paddingRight:e.spacing.sm,height:e.sizes.elementHighlightHeight,background:`transparent`,cursor:`pointer`,listStyle:`none`,minWidth:e.sizes.minMenuWidth,borderRadius:e.radii.md2,outline:`none`,transition:`background 50ms ease`,"&[data-focused]":{background:e.colors.darkenedBgMix15},"&[data-hovered]:not([data-disabled])":{background:e.colors.darkenedBgMix15},"&[data-disabled]":{cursor:`not-allowed`,opacity:.5}})),M={primary:f.PRIMARY,secondary:f.SECONDARY,tertiary:f.TERTIARY};function N(e){let{disabled:t,element:i,widgetMgr:o,fragmentId:l}=e,y=u(),[S,N]=(0,w.useState)(!1),P=(0,w.useId)(),F=(0,w.useRef)(null),{refs:I,floatingStyles:L}=h({open:S,placement:`bottom-start`,offsetPx:a(y.spacing.twoXS)}),{setFloatingRef:R,setReferenceRef:z}=g({isOpen:S,onClose:()=>N(!1),floatingSetFn:I.setFloating,referenceSetFn:I.setReference,restoreFocusFn:()=>F.current?.querySelector(`button`)?.focus(),closeOnTab:!0}),B=(0,w.useCallback)(e=>{F.current=e,z(e)},[z]),V=M[i.type]??f.SECONDARY,H=(0,w.useMemo)(()=>i.options.map(e=>({label:e,value:e})),[i.options]),U=t||i.disabled||i.options.length===0,W=v(i.icon,i.label),G=(0,w.useCallback)(e=>{if(U)return;let t=String(e).slice(P.length);o.setStringTriggerValue(i,t,{fromUi:!0},l),N(!1)},[U,i,o,l,P]);return r(c,{ref:B,className:`stMenuButton`,"data-testid":`stMenuButton`,children:[n(b,{help:i.help,containerWidth:!0,children:n(p,{"data-testid":`stMenuButtonButton`,kind:V,size:d.SMALL,disabled:U,containerWidth:!0,onClick:()=>N(e=>!e),"aria-haspopup":`menu`,"aria-expanded":S,children:r(T,{$hideChevron:W,children:[n(x,{icon:i.icon,label:i.label}),!W&&n(E,{"aria-hidden":`true`,children:n(_,{iconValue:S?`:material/expand_less:`:`:material/expand_more:`,size:`lg`})})]})})}),S&&n(m,{children:n(k,{ref:R,"data-testid":`stMenuButtonBody`,style:L,children:n(A,{onAction:G,"aria-label":C(i.label).text||`Menu`,autoFocus:`first`,children:H.map(e=>{let{icon:t,text:i}=C(e.label);return n(j,{id:`${P}${e.value}`,textValue:i,children:r(D,{children:[t&&n(O,{"aria-hidden":`true`,children:n(_,{iconValue:t,size:`md`})}),n(s,{source:i,allowHTML:!1,isLabel:!0,disableLinks:!0})]})},e.value)})})})})]})}var P=(0,w.memo)(N);export{P as default};