var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { UmbActionExecutedEvent } from '../../event/index.js';
import { html, nothing, ifDefined, customElement, property, state } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../lit-element/index.js';
let UmbEntityActionDefaultElement = class UmbEntityActionDefaultElement extends UmbLitElement {
    #api;
    set api(api) {
        this.#api = api;
        // TODO: Fix so when we use a HREF it does not refresh the page?
        this.#api?.getHref?.().then((href) => {
            this._href = href;
            // TODO: Do we need to update the component here? [NL]
        });
    }
    async focus() {
        await this.updateComplete;
        this.shadowRoot?.querySelector('uui-menu-item')?.focus();
    }
    async #onClickLabel(event) {
        if (!this._href) {
            event.stopPropagation();
            try {
                await this.#api?.execute();
                this.dispatchEvent(new UmbActionExecutedEvent());
            }
            catch (error) {
                console.error('Error executing action:', error);
            }
        }
    }
    // TODO: we need to stop the regular click event from bubbling up to the table so it doesn't select the row.
    // This should probably be handled in the UUI Menu item component. so we don't dispatch a label-click event and click event at the same time.
    #onClick(event) {
        event.stopPropagation();
    }
    render() {
        if (!this.manifest)
            return nothing;
        const label = this.manifest.meta.label ? this.localize.string(this.manifest.meta.label) : this.manifest.name;
        return html `
			<uui-menu-item
				data-mark=${'entity-action:' + this.manifest?.alias}
				label=${ifDefined(this.manifest?.meta.additionalOptions ? label + '…' : label)}
				href=${ifDefined(this._href)}
				@click-label=${this.#onClickLabel}
				@click=${this.#onClick}>
				${this.manifest.meta.icon ? html `<umb-icon slot="icon" name="${this.manifest.meta.icon}"></umb-icon>` : nothing}
			</uui-menu-item>
		`;
    }
};
__decorate([
    property({ type: String })
], UmbEntityActionDefaultElement.prototype, "entityType", void 0);
__decorate([
    property({ type: String })
], UmbEntityActionDefaultElement.prototype, "unique", void 0);
__decorate([
    property({ attribute: false })
], UmbEntityActionDefaultElement.prototype, "manifest", void 0);
__decorate([
    state()
], UmbEntityActionDefaultElement.prototype, "_href", void 0);
UmbEntityActionDefaultElement = __decorate([
    customElement('umb-entity-action')
], UmbEntityActionDefaultElement);
export { UmbEntityActionDefaultElement };
export default UmbEntityActionDefaultElement;
