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_MEMBER_WORKSPACE_CONTEXT } from '../../member-workspace.context-token.js';
import { UmbMemberKind } from '../../../../utils/index.js';
import { TimeFormatOptions } from './utils.js';
import { UmbTextStyles } from '../../../../../../core/style/index.js';
import { css, html, customElement, state, ifDefined } from '../../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../../core/lit-element/index.js';
import { UMB_WORKSPACE_MODAL } from '../../../../../../core/workspace/index.js';
import { UmbModalRouteRegistrationController } from '../../../../../../core/router/index.js';
import { UMB_MEMBER_TYPE_ENTITY_TYPE, UmbMemberTypeItemRepository } from '../../../../../member-type/index.js';
import { UMB_SECTION_USER_PERMISSION_CONDITION_ALIAS } from '../../../../../../core/section/index.js';
import { UMB_SETTINGS_SECTION_ALIAS } from '../../../../../../settings/index.js';
import { createExtensionApiByAlias } from '../../../../../../core/extension-registry/index.js';
let UmbMemberWorkspaceViewMemberInfoElement = class UmbMemberWorkspaceViewMemberInfoElement extends UmbLitElement {
    #workspaceContext;
    #memberTypeItemRepository;
    constructor() {
        super();
        this._memberTypeName = '';
        this._memberTypeIcon = '';
        this._editMemberTypePath = '';
        this._createDate = this.localize.term('general_unknown');
        this._updateDate = this.localize.term('general_unknown');
        this._unique = '';
        this._hasSettingsAccess = false;
        this.#memberTypeItemRepository = new UmbMemberTypeItemRepository(this);
        new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
            .addAdditionalPath('member-type')
            .onSetup(() => {
            return { data: { entityType: UMB_MEMBER_TYPE_ENTITY_TYPE, preset: {} } };
        })
            .observeRouteBuilder((routeBuilder) => {
            this._editMemberTypePath = routeBuilder({});
        });
        this.consumeContext(UMB_MEMBER_WORKSPACE_CONTEXT, async (context) => {
            this.#workspaceContext = context;
            this.observe(this.#workspaceContext?.contentTypeUnique, async (unique) => {
                if (unique === this._memberTypeUnique)
                    return;
                this._memberTypeUnique = unique;
                if (this._memberTypeUnique) {
                    const memberType = (await this.#memberTypeItemRepository.requestItems([this._memberTypeUnique])).data?.[0];
                    if (!memberType)
                        return;
                    this._memberTypeName = memberType.name;
                    this._memberTypeIcon = memberType.icon;
                }
            });
            this.observe(this.#workspaceContext?.createDate, (date) => (this._createDate = this.#setDateFormat(date)));
            this.observe(this.#workspaceContext?.updateDate, (date) => (this._updateDate = this.#setDateFormat(date)));
            this.observe(this.#workspaceContext?.unique, (unique) => (this._unique = unique || ''));
            this.observe(this.#workspaceContext?.kind, (kind) => (this._memberKind = kind));
        });
        createExtensionApiByAlias(this, UMB_SECTION_USER_PERMISSION_CONDITION_ALIAS, [
            {
                config: {
                    match: UMB_SETTINGS_SECTION_ALIAS,
                },
                onChange: (permitted) => {
                    this._hasSettingsAccess = permitted;
                },
            },
        ]);
    }
    #setDateFormat(date) {
        if (!date)
            return this.localize.term('general_unknown');
        return this.localize.date(date, TimeFormatOptions);
    }
    render() {
        return this.#renderGeneralSection();
    }
    #renderGeneralSection() {
        return html `
			<umb-stack look="compact">
				<div>
					<h4><umb-localize key="content_createDate">Created</umb-localize></h4>
					<span> ${this._createDate} </span>
				</div>
				<div>
					<h4><umb-localize key="content_updateDate">Last edited</umb-localize></h4>
					<span> ${this._updateDate} </span>
				</div>
				<div>
					<h4><umb-localize key="content_membertype">Member Type</umb-localize></h4>
					<uui-ref-node
						standalone
						.name=${this._memberTypeName}
						href=${ifDefined(this._hasSettingsAccess ? this._editMemberTypePath + 'edit/' + this._memberTypeUnique : undefined)}
						?readonly=${!this._hasSettingsAccess}>
						<umb-icon slot="icon" .name=${this._memberTypeIcon}></umb-icon>
					</uui-ref-node>
				</div>
				<div>
					<h4><umb-localize key="member_kind"></umb-localize></h4>
					<span
						>${this._memberKind === UmbMemberKind.API
            ? this.localize.term('member_memberKindApi')
            : this.localize.term('member_memberKindDefault')}</span
					>
				</div>
				<div>
					<h4><umb-localize key="template_id">Id</umb-localize></h4>
					<span>${this._unique}</span>
				</div>
			</umb-stack>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			h4 {
				margin: 0;
			}

			uui-ref-node[readonly] {
				padding-top: 7px;
				padding-bottom: 7px;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_memberTypeUnique", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_memberTypeName", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_memberTypeIcon", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_editMemberTypePath", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_createDate", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_updateDate", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_unique", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_memberKind", void 0);
__decorate([
    state()
], UmbMemberWorkspaceViewMemberInfoElement.prototype, "_hasSettingsAccess", void 0);
UmbMemberWorkspaceViewMemberInfoElement = __decorate([
    customElement('umb-member-workspace-view-member-info')
], UmbMemberWorkspaceViewMemberInfoElement);
export { UmbMemberWorkspaceViewMemberInfoElement };
export default UmbMemberWorkspaceViewMemberInfoElement;
