import{A as d,b as s,da as y,N as B,ay as g,c as n,at as M,ar as T,bV as I,aA as R,b4 as L,ax as v,j as x,aB as C,as as f,bW as E,E as O,aC as _,dE as w,G as A}from"./index.BdH_oWMm.js";import{S as k}from"./styled-components.BwP7eYqe.js";import{S as z}from"./stateful-menu.CLeMtMha.js";const N=d("div",{target:"e1cb2q0m0"})(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing.threeXS,marginRight:`calc(-${e.iconSizes.lg} * 0.25)`})),P=d("div",{target:"e1cb2q0m1"})(({theme:e})=>({display:"inline-flex",marginTop:e.spacing.threeXS})),X=d("div",{target:"e1cb2q0m2"})(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing.sm,whiteSpace:"nowrap"})),$=d("span",{target:"e1cb2q0m3"})(({theme:e})=>({display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,width:e.iconSizes.md,color:e.colors.bodyText})),D=d("li",{target:"e1cb2q0m4"})(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing.twoXS,marginBottom:e.spacing.twoXS,padding:0,background:"transparent",cursor:"pointer",listStyle:"none",minWidth:e.sizes.minMenuWidth})),W={primary:g.PRIMARY,secondary:g.SECONDARY,tertiary:g.TERTIARY},Y=s.memo(function({item:m,$isHighlighted:a,onClick:c,onMouseEnter:u,onKeyDown:i,$disabled:r,$isFocused:b,$size:t,resetMenu:h,renderAll:S,...l}){const{icon:p,text:o}=w(m.label);return n(D,{...l,role:"menuitem",onClick:c,onMouseEnter:u,onKeyDown:i,children:n(k,{$isHighlighted:a,children:x(X,{children:[p&&n($,{"aria-hidden":"true",children:n(f,{iconValue:p,size:"md"})}),n(A,{source:o,allowHTML:!1,isLabel:!0,largerLabel:!1,disableLinks:!0})]})})})});function q(e){const{disabled:m,element:a,widgetMgr:c,fragmentId:u}=e,[i,r]=s.useState(!1),b=s.useContext(y),t=B(),h=W[a.type]??g.SECONDARY,S=s.useMemo(()=>a.options.map(o=>({label:o,value:o})),[a.options]),l=m||a.disabled||a.options.length===0,p=s.useCallback(o=>{r(!1),!l&&c.setStringTriggerValue(a,o.item.value,{fromUi:!0},u)},[l,a,c,u]);return n(_,{className:"stMenuButton","data-testid":"stMenuButton",children:n(M,{triggerType:I.click,placement:T.bottomLeft,isOpen:i,onClickOutside:()=>r(!1),onEsc:()=>r(!1),ignoreBoundary:b,popoverMargin:O(t.spacing.twoXS),renderAll:!0,content:()=>n(z,{items:S,onItemSelect:p,overrides:{List:{props:{role:"menu"},style:{backgroundColor:t.colors.bgColor,paddingTop:t.spacing.threeXS,paddingBottom:t.spacing.threeXS,paddingLeft:t.spacing.xs,paddingRight:t.spacing.xs,boxShadow:"none",outline:"none"}},Option:{component:Y}}}),overrides:{Body:{props:{"data-testid":"stMenuButtonBody"},style:()=>({...E(t),borderTopLeftRadius:t.radii.xl,borderTopRightRadius:t.radii.xl,borderBottomRightRadius:t.radii.xl,borderBottomLeftRadius:t.radii.xl,marginRight:t.spacing.lg,marginBottom:t.spacing.lg,maxHeight:"70vh",overflow:"auto"})}},children:n("div",{children:n(R,{help:a.help,containerWidth:!0,children:n(L,{"data-testid":"stMenuButtonButton",kind:h,size:v.SMALL,disabled:l,containerWidth:!0,onClick:()=>r(!i),"aria-haspopup":"menu","aria-expanded":i,children:x(N,{children:[n(C,{icon:a.icon,label:a.label}),n(P,{"aria-hidden":"true",children:n(f,{iconValue:i?":material/expand_less:":":material/expand_more:",size:"lg"})})]})})})})})})}const H=s.memo(q);export{H as default};
