import{SubmenuController as e}from"./chunk.TNCUFN5S.js";import{menu_item_styles_default as t}from"./chunk.FKPAMLVJ.js";import{SlPopup as s}from"./chunk.NS3JH2ZN.js";import{LocalizeController as i}from"./chunk.2A3352EO.js";import{HasSlotController as o,getTextContent as a}from"./chunk.NYIIDP5N.js";import{SlIcon as n}from"./chunk.M4HIRIJ5.js";import{watch as r}from"./chunk.C7FWPEOY.js";import{ShoelaceElement as h}from"./chunk.Z7XDKKOD.js";import{__decorateClass as l}from"./chunk.6M63UXML.js";import{classMap as c}from"../../../../lit/directives/class-map.js";import{html as d}from"../../../../lit/index.js";import{property as u,query as m}from"../../../../lit/decorators.js";var p=class extends h{constructor(){super(...arguments),this.type="normal",this.checked=!1,this.value="",this.disabled=!1,this.localize=new i(this),this.hasSlotController=new o(this,"submenu"),this.submenuController=new e(this,this.hasSlotController,this.localize),this.handleHostClick=e=>{this.disabled&&(e.preventDefault(),e.stopImmediatePropagation())},this.handleMouseOver=e=>{this.focus(),e.stopPropagation()}}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleHostClick),this.addEventListener("mouseover",this.handleMouseOver)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleHostClick),this.removeEventListener("mouseover",this.handleMouseOver)}handleDefaultSlotChange(){const e=this.getTextLabel();void 0!==this.cachedTextLabel?e!==this.cachedTextLabel&&(this.cachedTextLabel=e,this.emit("slotchange",{bubbles:!0,composed:!1,cancelable:!1})):this.cachedTextLabel=e}handleCheckedChange(){if(this.checked&&"checkbox"!==this.type)return this.checked=!1,void console.error('The checked attribute can only be used on menu items with type="checkbox"',this);"checkbox"===this.type?this.setAttribute("aria-checked",this.checked?"true":"false"):this.removeAttribute("aria-checked")}handleDisabledChange(){this.setAttribute("aria-disabled",this.disabled?"true":"false")}handleTypeChange(){"checkbox"===this.type?(this.setAttribute("role","menuitemcheckbox"),this.setAttribute("aria-checked",this.checked?"true":"false")):(this.setAttribute("role","menuitem"),this.removeAttribute("aria-checked"))}getTextLabel(){return a(this.defaultSlot)}isSubmenu(){return this.hasSlotController.test("submenu")}render(){const e="rtl"===this.localize.dir(),t=this.submenuController.isExpanded();return d`
      <div
        id="anchor"
        part="base"
        class=${c({"menu-item":!0,"menu-item--rtl":e,"menu-item--checked":this.checked,"menu-item--disabled":this.disabled,"menu-item--has-submenu":this.isSubmenu(),"menu-item--submenu-expanded":t})}
        ?aria-haspopup="${this.isSubmenu()}"
        ?aria-expanded="${!!t}"
      >
        <span part="checked-icon" class="menu-item__check">
          <sl-icon name="check" library="system" aria-hidden="true"></sl-icon>
        </span>

        <slot name="prefix" part="prefix" class="menu-item__prefix"></slot>

        <slot part="label" class="menu-item__label" @slotchange=${this.handleDefaultSlotChange}></slot>

        <slot name="suffix" part="suffix" class="menu-item__suffix"></slot>

        <span part="submenu-icon" class="menu-item__chevron">
          <sl-icon name=${e?"chevron-left":"chevron-right"} library="system" aria-hidden="true"></sl-icon>
        </span>

        ${this.submenuController.renderSubmenu()}
      </div>
    `}};p.styles=t,p.dependencies={"sl-icon":n,"sl-popup":s},l([m("slot:not([name])")],p.prototype,"defaultSlot",2),l([m(".menu-item")],p.prototype,"menuItem",2),l([u()],p.prototype,"type",2),l([u({type:Boolean,reflect:!0})],p.prototype,"checked",2),l([u()],p.prototype,"value",2),l([u({type:Boolean,reflect:!0})],p.prototype,"disabled",2),l([r("checked")],p.prototype,"handleCheckedChange",1),l([r("disabled")],p.prototype,"handleDisabledChange",1),l([r("type")],p.prototype,"handleTypeChange",1);export{p as SlMenuItem};