/**
 * Copyright Aquera Inc 2026
 *
 * This source code is licensed under the BSD-3-Clause license found in the
 * LICENSE file in the root directory of this source tree.
 */
import { __decorate } from "tslib";
import { html, nothing } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { styles } from './nile-context-menu-item.css';
import NileElement from '../internal/nile-element';
/**
 * Nile context-menu item. A clickable entry inside `nile-context-menu`.
 *
 * @tag nile-context-menu-item
 *
 * @slot - Default slot for the visible label.
 * @slot icon - Optional leading icon (e.g. a `<nile-glyph slot="icon">`).
 */
let NileContextMenuItem = class NileContextMenuItem extends NileElement {
    constructor() {
        super(...arguments);
        this.value = '';
        this.disabled = false;
        this._hasSubmenu = false;
        this._hasIcon = false;
        this._submenuExpanded = false;
        this._onSlotChange = (e) => {
            const slot = e.target;
            const nodes = slot.assignedElements({ flatten: true });
            this._hasSubmenu = nodes.some(n => n.tagName.toLowerCase() === 'nile-context-submenu');
        };
        this._onIconSlotChange = (e) => {
            const slot = e.target;
            this._hasIcon = slot.assignedNodes({ flatten: true }).some(n => n.nodeType === Node.ELEMENT_NODE || (n.textContent ?? '').trim() !== '');
        };
    }
    static get styles() {
        return [styles];
    }
    setSubmenuExpanded(expanded) {
        this._submenuExpanded = expanded;
    }
    focus(options) {
        const inner = this.shadowRoot?.querySelector('.item');
        inner?.focus(options);
    }
    get hasSubmenu() {
        return this._hasSubmenu;
    }
    render() {
        return html `
      <div
        part="item"
        class="item"
        role="menuitem"
        tabindex="-1"
        aria-disabled=${this.disabled ? 'true' : 'false'}
        aria-haspopup=${this._hasSubmenu ? 'menu' : nothing}
        aria-expanded=${this._hasSubmenu ? String(this._submenuExpanded) : nothing}
        data-has-submenu=${this._hasSubmenu ? 'true' : 'false'}
      >
        <span part="icon" class="icon" data-empty=${this._hasIcon ? 'false' : 'true'}>
          <slot name="icon" @slotchange=${this._onIconSlotChange}></slot>
        </span>
        <span part="label" class="label"><slot @slotchange=${this._onSlotChange}></slot></span>
        ${this._hasSubmenu
            ? html `<span part="chevron" class="chevron" aria-hidden="true">
              <nile-glyph name="ng-chevron-right" size="16"></nile-glyph>
            </span>`
            : ''}
      </div>
    `;
    }
};
__decorate([
    property({ attribute: true, type: String, reflect: true })
], NileContextMenuItem.prototype, "value", void 0);
__decorate([
    property({ attribute: true, type: Boolean, reflect: true })
], NileContextMenuItem.prototype, "disabled", void 0);
__decorate([
    state()
], NileContextMenuItem.prototype, "_hasSubmenu", void 0);
__decorate([
    state()
], NileContextMenuItem.prototype, "_hasIcon", void 0);
__decorate([
    state()
], NileContextMenuItem.prototype, "_submenuExpanded", void 0);
NileContextMenuItem = __decorate([
    customElement('nile-context-menu-item')
], NileContextMenuItem);
export { NileContextMenuItem };
export default NileContextMenuItem;
//# sourceMappingURL=nile-context-menu-item.js.map