import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { d as defineCustomElement$3 } from './pds-icon2.js';
import { d as defineCustomElement$2 } from './pds-link2.js';

const pdsDropdownMenuItemCss = ":host{cursor:pointer;display:-ms-flexbox;display:flex;width:100%;}:host(.is-disabled){cursor:not-allowed !important;opacity:0.5 !important}:host(.is-disabled) .pds-dropdown-menu-item__content{cursor:not-allowed !important;pointer-events:none !important}.pds-dropdown-menu-item__content{-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;border:0;border-radius:var(--pine-dimension-xs);color:var(--pine-color-text);display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;font:var(--pine-typography-body-medium);gap:var(--pine-dimension-xs);margin:calc(var(--pine-border-width) + 2px);padding:var(--pine-dimension-xs);text-align:start;width:100%;}.pds-dropdown-menu-item__content:hover{background-color:var(--pine-color-background-muted);color:var(--pine-color-text-hover)}.pds-dropdown-menu-item__content{}.pds-dropdown-menu-item__content:focus,.pds-dropdown-menu-item__content:focus-visible,.pds-dropdown-menu-item__content.has-focus{outline:var(--pine-outline-focus);outline-offset:var(--pine-border-width)}:host(.destructive) .pds-dropdown-menu-item__content{--pds-context-link-color:var(--pine-color-danger);--pds-context-link-color-hover:var(--pine-color-danger-hover);-ms-flex-align:center;align-items:center;color:var(--pine-color-danger)}:host(.destructive) .pds-dropdown-menu-item__content:hover{background-color:var(--pine-color-danger-disabled);color:var(--pine-color-danger-hover)}:host(.destructive) .pds-dropdown-menu-item__content:focus,:host(.destructive) .pds-dropdown-menu-item__content:focus-visible,:host(.destructive) .pds-dropdown-menu-item__content.has-focus{background-color:var(--pine-color-danger-disabled);outline:var(--pine-outline-focus-danger);outline-offset:var(--pine-border-width)}pds-link::part(link):focus,pds-link::part(link):focus-visible{-webkit-box-shadow:none;box-shadow:none;outline:none}pds-link::part(link){-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;gap:var(--pine-dimension-xs);margin:calc(var(--pine-dimension-xs) * -1);padding:var(--pine-dimension-xs);text-decoration:none;width:calc(100% + var(--pine-dimension-xs) * 2)}";

const PdsDropdownMenuItem$1 = /*@__PURE__*/ proxyCustomElement(class PdsDropdownMenuItem extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.__attachShadow();
        this.pdsClick = createEvent(this, "pdsClick", 7);
        /**
         * It determines whether or not the dropdown-item is destructive.
         * @defaultValue false
         */
        this.destructive = false;
        /**
         * It determines whether or not the dropdown-item is disabled.
         * @defaultValue false
         */
        this.disabled = false;
        /**
         * Determines whether the link should open in a new tab and display an external icon.
         * This is a simpler alternative to using `target="_blank"` for the common case.
         * @defaultValue false
         */
        this.external = false;
        this.hasFocus = false;
        this.handleFocus = () => {
            this.hasFocus = true;
        };
        this.handleBlur = () => {
            this.hasFocus = false;
        };
        this.handleKeyDown = (event) => {
            // Handle keyboard events
            if (!this.disabled && (event.key === 'Enter')) {
                // Only prevent default for button elements or Space key
                // For links with Enter key, we want the default navigation behavior
                if (!this.href) {
                    event.preventDefault();
                }
                this.handleClick();
            }
        };
    }
    /**
     * Trigger the click event
     */
    async clickItem() {
        this.handleClick();
    }
    ;
    handleClick() {
        var _a;
        // Filter only pds-dropdown-menu-item elements and find the index of the current item
        const menuItems = Array.from(this.host.parentNode.children).filter((child) => child.tagName.toLowerCase() === 'pds-dropdown-menu-item');
        const itemIndex = menuItems.indexOf(this.host);
        // Get the text content from the slotted content
        const content = ((_a = this.host.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
        this.pdsClick.emit({
            itemIndex,
            item: this.host,
            content
        });
    }
    renderElement() {
        if (this.href !== undefined) {
            return (h("pds-link", { download: this.download, href: this.disabled ? null : this.href, external: this.external, target: this.target, class: {
                    'pds-dropdown-menu-item__content': true,
                    'has-focus': this.hasFocus
                }, tabIndex: this.disabled ? -1 : 0, onKeyDown: this.handleKeyDown, onFocus: this.handleFocus, onBlur: this.handleBlur, "aria-disabled": this.disabled ? 'true' : null }, h("slot", null)));
        }
        return (h("button", { class: {
                'pds-dropdown-menu-item__content': true,
                'has-focus': this.hasFocus
            }, tabIndex: this.disabled ? -1 : 0, type: "button", part: "button", onKeyDown: this.handleKeyDown, onFocus: this.handleFocus, onBlur: this.handleBlur, disabled: this.disabled, "aria-disabled": this.disabled ? 'true' : null }, h("slot", null)));
    }
    render() {
        return (h(Host, { key: 'd2a6c182b330dae3738650002a4643c0f1fd3d1a', id: this.componentId, class: { 'is-disabled': this.disabled, 'destructive': !this.disabled && this.destructive }, onClick: () => !this.disabled && this.handleClick(), role: "none", tabIndex: -1, "aria-disabled": this.disabled ? 'true' : null }, this.renderElement()));
    }
    get host() { return this; }
    static get style() { return pdsDropdownMenuItemCss; }
}, [257, "pds-dropdown-menu-item", {
        "componentId": [1, "component-id"],
        "destructive": [4],
        "disabled": [516],
        "download": [1],
        "href": [1],
        "external": [516],
        "target": [513],
        "hasFocus": [32],
        "clickItem": [64]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["pds-dropdown-menu-item", "pds-icon", "pds-link"];
    components.forEach(tagName => { switch (tagName) {
        case "pds-dropdown-menu-item":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, PdsDropdownMenuItem$1);
            }
            break;
        case "pds-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "pds-link":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const PdsDropdownMenuItem = PdsDropdownMenuItem$1;
const defineCustomElement = defineCustomElement$1;

export { PdsDropdownMenuItem, defineCustomElement };
//# sourceMappingURL=pds-dropdown-menu-item.js.map

//# sourceMappingURL=pds-dropdown-menu-item.js.map