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_DOCUMENT_ENTITY_TYPE } from '../entity.js';
import { UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN } from '../paths.js';
import { UmbDocumentItemDataResolver } from './document-item-data-resolver.js';
import { customElement, html, ifDefined, nothing, property, state } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import { UmbModalRouteRegistrationController } from '../../../core/router/index.js';
import { UMB_WORKSPACE_MODAL } from '../../../core/workspace/index.js';
import { UmbDeselectedEvent, UmbSelectedEvent } from '../../../core/event/index.js';
let UmbDocumentItemRefElement = class UmbDocumentItemRefElement extends UmbLitElement {
    #item;
    set item(value) {
        this.#item.setData(value);
    }
    get item() {
        return this.#item.getData();
    }
    constructor() {
        super();
        this.#item = new UmbDocumentItemDataResolver(this);
        this.readonly = false;
        this.standalone = false;
        this.selectOnly = false;
        this.selectable = false;
        this.selected = false;
        this.disabled = false;
        this._unique = '';
        this._name = '';
        this._icon = '';
        this._isTrashed = false;
        this._isDraft = false;
        this._editPath = '';
        new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
            .addUniquePaths(['unique'])
            .onSetup(() => {
            return { data: { entityType: UMB_DOCUMENT_ENTITY_TYPE, preset: {} } };
        })
            .observeRouteBuilder((routeBuilder) => {
            this._editPath = routeBuilder({});
        });
        this.#item.observe(this.#item.unique, (unique) => (this._unique = unique ?? ''));
        this.#item.observe(this.#item.name, (name) => (this._name = name ?? ''));
        this.#item.observe(this.#item.icon, (icon) => (this._icon = icon ?? ''));
        this.#item.observe(this.#item.isTrashed, (isTrashed) => (this._isTrashed = isTrashed ?? false));
        this.#item.observe(this.#item.isDraft, (isDraft) => (this._isDraft = isDraft ?? false));
    }
    #getHref() {
        if (!this._unique)
            return;
        const path = UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({ unique: this._unique });
        return `${this._editPath}/${path}`;
    }
    #onSelected(event) {
        event.stopPropagation();
        this.dispatchEvent(new UmbSelectedEvent(this._unique));
    }
    #onDeselected(event) {
        event.stopPropagation();
        this.dispatchEvent(new UmbDeselectedEvent(this._unique));
    }
    render() {
        if (!this.item)
            return nothing;
        return html `
			<uui-ref-node
				name=${this._name}
				href=${ifDefined(this.#getHref())}
				?readonly=${this.readonly}
				?standalone=${this.standalone}
				?select-only=${this.selectOnly}
				?selectable=${this.selectable}
				?selected=${this.selected}
				?disabled=${this.disabled}
				@selected=${this.#onSelected}
				@deselected=${this.#onDeselected}>
				<slot name="actions" slot="actions"></slot>
				${this.#renderIcon()}${this.#renderIsDraft()} ${this.#renderIsTrashed()}
			</uui-ref-node>
		`;
    }
    #renderIcon() {
        if (!this._icon)
            return nothing;
        return html `<umb-icon slot="icon" name=${this._icon}></umb-icon>`;
    }
    #renderIsTrashed() {
        if (!this._isTrashed)
            return nothing;
        return html `<uui-tag size="s" slot="tag" color="danger">Trashed</uui-tag>`;
    }
    #renderIsDraft() {
        if (!this._isDraft)
            return nothing;
        return html `<uui-tag size="s" slot="tag" look="secondary" color="default">Draft</uui-tag>`;
    }
};
__decorate([
    property({ type: Object })
], UmbDocumentItemRefElement.prototype, "item", null);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbDocumentItemRefElement.prototype, "readonly", void 0);
__decorate([
    property({ type: Boolean })
], UmbDocumentItemRefElement.prototype, "standalone", void 0);
__decorate([
    property({ type: Boolean, attribute: 'select-only', reflect: true })
], UmbDocumentItemRefElement.prototype, "selectOnly", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbDocumentItemRefElement.prototype, "selectable", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbDocumentItemRefElement.prototype, "selected", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbDocumentItemRefElement.prototype, "disabled", void 0);
__decorate([
    state()
], UmbDocumentItemRefElement.prototype, "_unique", void 0);
__decorate([
    state()
], UmbDocumentItemRefElement.prototype, "_name", void 0);
__decorate([
    state()
], UmbDocumentItemRefElement.prototype, "_icon", void 0);
__decorate([
    state()
], UmbDocumentItemRefElement.prototype, "_isTrashed", void 0);
__decorate([
    state()
], UmbDocumentItemRefElement.prototype, "_isDraft", void 0);
__decorate([
    state()
], UmbDocumentItemRefElement.prototype, "_editPath", void 0);
UmbDocumentItemRefElement = __decorate([
    customElement('umb-document-item-ref')
], UmbDocumentItemRefElement);
export { UmbDocumentItemRefElement };
export { UmbDocumentItemRefElement as element };
