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 { UMB_PROPERTY_SORT_MODE_CONTEXT } from '../property-context/property-sort-mode.context-token.js';
import { customElement, html, property, state, when } from '../../../../external/lit/index.js';
import { UmbActionExecutedEvent } from '../../event/index.js';
import { UmbLitElement } from '../../lit-element/index.js';
let UmbPropertySortModePropertyActionElement = class UmbPropertySortModePropertyActionElement extends UmbLitElement {
    constructor() {
        super();
        this._isSortMode = false;
        this.consumeContext(UMB_PROPERTY_SORT_MODE_CONTEXT, (context) => {
            this.observe(context?.isSortMode, (isSortMode) => (this._isSortMode = isSortMode ?? false));
        });
    }
    async #onClickLabel(event) {
        event.stopPropagation();
        await this.api?.execute().catch(() => { });
        this.dispatchEvent(new UmbActionExecutedEvent());
    }
    // 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() {
        const label = this._isSortMode ? 'blockEditor_actionExitSortMode' : 'blockEditor_actionEnterSortMode';
        return html `
			<uui-menu-item label=${this.localize.term(label)} @click-label=${this.#onClickLabel} @click=${this.#onClick}>
				${when(this.manifest?.meta.icon, (icon) => html `<umb-icon slot="icon" name=${icon}></umb-icon>`)}
			</uui-menu-item>
		`;
    }
};
__decorate([
    state()
], UmbPropertySortModePropertyActionElement.prototype, "_isSortMode", void 0);
__decorate([
    property({ attribute: false })
], UmbPropertySortModePropertyActionElement.prototype, "manifest", void 0);
__decorate([
    property({ attribute: false })
], UmbPropertySortModePropertyActionElement.prototype, "api", void 0);
UmbPropertySortModePropertyActionElement = __decorate([
    customElement('umb-property-sort-mode-property-action')
], UmbPropertySortModePropertyActionElement);
export { UmbPropertySortModePropertyActionElement };
export { UmbPropertySortModePropertyActionElement as element };
