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_MEDIA_SECTION_ALIAS } from '../../media-section/constants.js';
import { UMB_MEDIA_ENTITY_TYPE } from '../entity.js';
import { UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN } from '../paths.js';
import { createExtensionApiByAlias } from '../../../core/extension-registry/index.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_SECTION_USER_PERMISSION_CONDITION_ALIAS } from '../../../core/section/index.js';
import { UMB_WORKSPACE_MODAL } from '../../../core/workspace/index.js';
let UmbMediaItemRefElement = class UmbMediaItemRefElement extends UmbLitElement {
    #item;
    get item() {
        return this.#item;
    }
    set item(value) {
        this.#item = value;
    }
    constructor() {
        super();
        this.readonly = false;
        this.standalone = false;
        this._editPath = '';
        this._userHasSectionAccess = false;
        createExtensionApiByAlias(this, UMB_SECTION_USER_PERMISSION_CONDITION_ALIAS, [
            {
                config: {
                    match: UMB_MEDIA_SECTION_ALIAS,
                },
                onChange: (permitted) => {
                    this._userHasSectionAccess = permitted;
                },
            },
        ]);
        new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
            .addUniquePaths(['unique'])
            .onSetup(() => {
            return { data: { entityType: UMB_MEDIA_ENTITY_TYPE, preset: {} } };
        })
            .observeRouteBuilder((routeBuilder) => {
            this._editPath = routeBuilder({});
        });
    }
    #getHref(item) {
        if (!this._editPath)
            return;
        const path = UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN.generateLocal({ unique: item.unique });
        return `${this._editPath}/${path}`;
    }
    render() {
        if (!this.item)
            return nothing;
        return html `
			<uui-ref-node
				name=${this.item.name}
				href=${ifDefined(this.#getHref(this.item))}
				?readonly=${this.readonly || !this._userHasSectionAccess}
				?standalone=${this.standalone}>
				<slot name="actions" slot="actions"></slot>
				${this.#renderIcon(this.item)}
			</uui-ref-node>
		`;
    }
    #renderIcon(item) {
        if (!item.mediaType.icon)
            return;
        return html `<umb-icon slot="icon" name=${item.mediaType.icon}></umb-icon>`;
    }
};
__decorate([
    property({ type: Object })
], UmbMediaItemRefElement.prototype, "item", null);
__decorate([
    property({ type: Boolean })
], UmbMediaItemRefElement.prototype, "readonly", void 0);
__decorate([
    property({ type: Boolean })
], UmbMediaItemRefElement.prototype, "standalone", void 0);
__decorate([
    state()
], UmbMediaItemRefElement.prototype, "_editPath", void 0);
__decorate([
    state()
], UmbMediaItemRefElement.prototype, "_userHasSectionAccess", void 0);
UmbMediaItemRefElement = __decorate([
    customElement('umb-media-item-ref')
], UmbMediaItemRefElement);
export { UmbMediaItemRefElement };
export { UmbMediaItemRefElement as element };
