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_WORKSPACE_CONTEXT } from '../../media-workspace.context-token.js';
import { TimeOptions } from '../../../audit-log/info-app/utils.js';
import { css, customElement, html, ifDefined, nothing, state } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import { UMB_MEDIA_TYPE_ENTITY_TYPE, UmbMediaTypeItemRepository } from '../../../../media-types/index.js';
import { UmbModalRouteRegistrationController } from '../../../../../core/router/index.js';
import { UmbTextStyles } from '../../../../../core/style/index.js';
import { UMB_WORKSPACE_MODAL } from '../../../../../core/workspace/index.js';
import { createExtensionApiByAlias } from '../../../../../core/extension-registry/index.js';
import { UMB_SECTION_USER_PERMISSION_CONDITION_ALIAS } from '../../../../../core/section/index.js';
import { UMB_SETTINGS_SECTION_ALIAS } from '../../../../../settings/index.js';
import { UMB_IS_TRASHED_ENTITY_CONTEXT } from '../../../../../core/recycle-bin/index.js';
let UmbMediaWorkspaceViewInfoElement = class UmbMediaWorkspaceViewInfoElement extends UmbLitElement {
    #workspaceContext;
    #mediaTypeItemRepository;
    constructor() {
        super();
        this._mediaTypeUnique = undefined;
        this._editMediaTypePath = '';
        this._mediaUnique = '';
        this.#mediaTypeItemRepository = new UmbMediaTypeItemRepository(this);
        this._createDate = null;
        this._updateDate = null;
        this._hasSettingsAccess = false;
        this._isTrashed = false;
        new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
            .addAdditionalPath('media-type')
            .onSetup(() => {
            return { data: { entityType: UMB_MEDIA_TYPE_ENTITY_TYPE, preset: {} } };
        })
            .observeRouteBuilder((routeBuilder) => {
            this._editMediaTypePath = routeBuilder({});
        });
        createExtensionApiByAlias(this, UMB_SECTION_USER_PERMISSION_CONDITION_ALIAS, [
            {
                config: {
                    match: UMB_SETTINGS_SECTION_ALIAS,
                },
                onChange: (permitted) => {
                    this._hasSettingsAccess = permitted;
                },
            },
        ]);
        this.consumeContext(UMB_MEDIA_WORKSPACE_CONTEXT, (context) => {
            this.#workspaceContext = context;
            this._mediaTypeUnique = context?.getContentTypeId();
            this.#getData();
            this.#observeContent();
        });
        this.consumeContext(UMB_IS_TRASHED_ENTITY_CONTEXT, (context) => {
            this.observe(context?.isTrashed, (isTrashed) => {
                this._isTrashed = isTrashed ?? false;
            }, '_isTrashed');
        });
    }
    async #getData() {
        if (!this.#workspaceContext)
            return;
        if (!this._mediaTypeUnique)
            throw new Error('Media type unique is not set');
        const { data } = await this.#mediaTypeItemRepository.requestItems([this._mediaTypeUnique]);
        this._mediaTypeName = data?.[0].name;
        this._mediaTypeIcon = data?.[0].icon;
    }
    #observeContent() {
        this.observe(this.#workspaceContext?.unique, (unique) => {
            this._mediaUnique = unique;
        }, '_mediaUnique');
        /** TODO: Doubt this is the right way to get the create date... */
        this.observe(this.#workspaceContext?.variants, (variants) => {
            this._createDate = variants?.[0]?.createDate;
            this._updateDate = variants?.[0]?.updateDate;
        }, 'observeVariants');
    }
    render() {
        return html `
			<div class="container">
				<umb-extension-slot id="workspace-info-apps" type="workspaceInfoApp"></umb-extension-slot>
			</div>
			<div class="container">
				<uui-box headline=${this.localize.term('general_general')} id="general-section"
					>${this.#renderGeneralSection()}</uui-box
				>
			</div>
		`;
    }
    #renderGeneralSection() {
        return html `
			${this.#renderTrashState()} ${this.#renderCreateDate()} ${this.#renderUpdateDate()}
			<div class="general-item">
				<strong><umb-localize key="content_mediaType">Media Type</umb-localize></strong>
				<uui-ref-node-document-type
					standalone
					href=${ifDefined(this._hasSettingsAccess ? this._editMediaTypePath + 'edit/' + this._mediaTypeUnique : undefined)}
					?readonly=${!this._hasSettingsAccess || this._isTrashed}
					name=${ifDefined(this._mediaTypeName)}>
					${this._mediaTypeIcon ? html `<umb-icon slot="icon" name=${this._mediaTypeIcon}></umb-icon>` : nothing}
				</uui-ref-node-document-type>
			</div>
			<div class="general-item">
				<strong><umb-localize key="template_id">Id</umb-localize></strong>
				<span>${this._mediaUnique}</span>
			</div>
		`;
    }
    #renderTrashState() {
        if (!this._isTrashed)
            return nothing;
        return html `
			<div class="general-item">
				<span>
					<uui-tag color="danger" look="primary" label=${this.localize.term('content_trashed')}>
						${this.localize.term('content_trashed')}
					</uui-tag>
				</span>
			</div>
		`;
    }
    #renderCreateDate() {
        if (!this._createDate)
            return nothing;
        return html `
			<div class="general-item">
				<strong><umb-localize key="content_createDate"></umb-localize></strong>
				<span>
					<umb-localize-date .date=${this._createDate} .options=${TimeOptions}></umb-localize-date>
				</span>
			</div>
		`;
    }
    #renderUpdateDate() {
        if (!this._updateDate)
            return nothing;
        return html `
			<div class="general-item">
				<strong><umb-localize key="content_updateDate"></umb-localize></strong>
				<span>
					<umb-localize-date .date=${this._updateDate} .options=${TimeOptions}></umb-localize-date>
				</span>
			</div>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: grid;
				gap: var(--uui-size-layout-1);
				padding: var(--uui-size-layout-1);
				grid-template-columns: 1fr 350px;
			}

			div.container {
				display: flex;
				flex-direction: column;
				gap: var(--uui-size-layout-1);
			}

			//General section

			#general-section {
				display: flex;
				flex-direction: column;
			}

			.general-item {
				display: flex;
				flex-direction: column;
				gap: var(--uui-size-space-1);
			}

			.general-item:not(:last-child) {
				margin-bottom: var(--uui-size-space-6);
			}

			uui-ref-node-document-type[readonly] {
				padding-top: 7px;
				padding-bottom: 7px;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_mediaTypeUnique", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_mediaTypeName", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_mediaTypeIcon", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_editMediaTypePath", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_mediaUnique", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_createDate", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_updateDate", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_hasSettingsAccess", void 0);
__decorate([
    state()
], UmbMediaWorkspaceViewInfoElement.prototype, "_isTrashed", void 0);
UmbMediaWorkspaceViewInfoElement = __decorate([
    customElement('umb-media-workspace-view-info')
], UmbMediaWorkspaceViewInfoElement);
export { UmbMediaWorkspaceViewInfoElement };
export default UmbMediaWorkspaceViewInfoElement;
