"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index21.css');const s=require("react/jsx-runtime"),_=require("../../classix-5H4IWnMA.cjs"),d=require("react"),b=require("../button/index.cjs"),p=require("../icon/index.cjs"),h=require("../list/index.cjs"),j=require("../popover/index.cjs"),y="_list_1x03m_1",D="_item_1x03m_13",q="_danger_1x03m_41",f={list:y,item:D,danger:q};function k(o){return o.filter(t=>!!(t&&!t.disabled))}const w=({close:o,initialFocus:t,items:i,menuAccessibleLabel:u,onItemSelect:a})=>{const l=d.useRef([]),r=d.useCallback(e=>{const n=k(l.current);if(n.length===0)return;if(e==="first"){n[0].focus();return}if(e==="last"){n[n.length-1].focus();return}const c=n.indexOf(document.activeElement),g=e==="next"?(c+1)%n.length:(c-1+n.length)%n.length;n[g].focus()},[]);d.useEffect(()=>{r(t??"first")},[r,t]);const m=e=>{if(e.key==="ArrowDown"){e.preventDefault(),r("next");return}if(e.key==="ArrowUp"){e.preventDefault(),r("previous");return}if(e.key==="Home"){e.preventDefault(),r("first");return}e.key==="End"&&(e.preventDefault(),r("last"))},x=e=>{var n;(n=e.onSelect)==null||n.call(e),a==null||a(e),o()};return s.jsx(h.List,{"aria-label":u,className:f.list,onKeyDown:m,role:"menu","data-component":"menupanel",children:i.map((e,n)=>s.jsx("li",{role:"none",children:s.jsxs(b.Button,{"aria-label":e.accessibleLabel,className:_.t(f.item,e.isDanger&&f.danger),disabled:e.disabled,onClick:()=>x(e),ref:c=>{l.current[n]=c},role:"menuitem",variant:"minimal",children:[e.icon&&s.jsx(p.Icon,{gap:"right",name:e.icon,size:"small",variant:e.isDanger?"danger":"default"}),s.jsx("span",{children:e.label})]})},e.id??n))})},M=({items:o,menuAccessibleLabel:t="Menu",onItemSelect:i,position:u="left",triggerAccessibleLabel:a="Open menu"})=>s.jsx(j.Popover,{position:u,triggerAccessibleLabel:a,triggerAriaHasPopup:"menu",triggerButtonContent:s.jsx(p.Icon,{name:"dots",size:"medium"}),"data-component":"menu",children:({close:l,initialFocus:r})=>s.jsx(w,{close:l,initialFocus:r,items:o,menuAccessibleLabel:t,onItemSelect:i})});exports.Menu=M;
//# sourceMappingURL=index.cjs.map
