import{a as w}from"./chunk.VAM5SM3O.js";import{a as p,d as f,h as m}from"./chunk.XJAJO727.js";import{b as u,e as h}from"./chunk.OBAEIKIV.js";import{e as c}from"./chunk.6EV4YU6C.js";var a=class extends m{constructor(){super(...arguments);this.localize=new w(this);this.handleOutsideClick=t=>{this.contains(t.target)||this.getAllItems().forEach(e=>e.classList.remove("menu-item-focus"))}}connectedCallback(){super.connectedCallback(),this.setAttribute("role","menu"),document.addEventListener("click",this.handleOutsideClick)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this.handleOutsideClick)}handleClick(t){let e=["menuitem","menuitemcheckbox"],n=t.composedPath(),i=n.find(s=>{var l;return e.includes(((l=s==null?void 0:s.getAttribute)==null?void 0:l.call(s,"role"))||"")});if(!i||n.find(s=>{var l;return((l=s==null?void 0:s.getAttribute)==null?void 0:l.call(s,"role"))==="menu"})!==this)return;let o=i;o.type==="checkbox"&&(o.checked=!o.checked),this.emit("sd-select",{detail:{item:o}})}handleKeyDown(t){if(t.key==="Escape"){let e=this.getCurrentItem();e==null||e.classList.remove("menu-item-focus")}else if(t.key==="Enter"||t.key===" "){let e=this.getCurrentItem();t.preventDefault(),t.stopPropagation(),e==null||e.classList.remove("menu-item-focus"),e==null||e.click()}else if(["ArrowDown","ArrowUp","Home","End"].includes(t.key)){let e=this.getAllItems(),n=this.getCurrentItem(),i=n?e.indexOf(n):0;if(n==null||n.classList.remove("menu-item-focus"),e.length>0){t.preventDefault(),t.stopPropagation();let d=(r,o)=>{let s=r;for(let l of e)if(s=(s+o+e.length)%e.length,!e[s].disabled)return s;return r};if(t.key==="ArrowDown")i=d(i,1);else if(t.key==="ArrowUp")i=d(i,-1);else if(t.key==="Home")i=e.findIndex(r=>!r.disabled),i===-1&&(i=0);else if(t.key==="End"){i=e.length-1;for(let r=e.length-1;r>=0;r--)if(!e[r].disabled){i=r;break}}this.setCurrentItem(e[i]),e[i].focus(),e[i].classList.add("menu-item-focus")}}}handleMouseDown(t){let e=t.target;this.isMenuItem(e)&&this.setCurrentItem(e)}handleSlotChange(){let t=this.getAllItems();t.length>0&&this.setCurrentItem(t[0])}isMenuItem(t){var e;return t.tagName.toLowerCase()==="sd-menu-item"||["menuitem","menuitemcheckbox","menuitemradio"].includes((e=t.getAttribute("role"))!=null?e:"")}getAllItems(){return[...this.defaultSlot.assignedElements({flatten:!0})].filter(t=>!!this.isMenuItem(t))}getCurrentItem(){return this.getAllItems().find(t=>t.getAttribute("tabindex")==="0")}setCurrentItem(t){this.getAllItems().forEach(n=>{n.setAttribute("tabindex",n===t?"0":"-1")})}render(){return h`<slot @slotchange="${this.handleSlotChange}" @click="${this.handleClick}" @keydown="${this.handleKeyDown}" @mousedown="${this.handleMouseDown}"></slot>`}};a.styles=[...m.styles,u`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */@layer properties;@layer theme,base,components,utilities;
:host{position:relative;display:block;overflow:auto;overscroll-behavior:auto;border-radius:var(--sd-radius-md);padding-inline:var(--sd-spacing-2);padding-block:var(--sd-spacing-3);--tw-shadow:var(--sd-shadow)!important;box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)!important}::slotted(sd-divider){padding-block:var(--sd-spacing-3)}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}`],c([f("slot")],a.prototype,"defaultSlot",2),a=c([p("sd-menu")],a);export{a};
