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_TYPE_WORKSPACE_CONTEXT } from '../../document-type-workspace.context-token.js';
import { css, html, customElement, state } from '../../../../../../../external/lit/index.js';
import { UmbTextStyles } from '../../../../../../core/style/index.js';
import { UmbLitElement } from '../../../../../../core/lit-element/index.js';
let UmbDocumentTypeWorkspaceViewStructureElement = class UmbDocumentTypeWorkspaceViewStructureElement extends UmbLitElement {
    #workspaceContext;
    constructor() {
        super();
        this.consumeContext(UMB_DOCUMENT_TYPE_WORKSPACE_CONTEXT, (documentTypeContext) => {
            this.#workspaceContext = documentTypeContext;
            this._observeDocumentType();
        });
    }
    _observeDocumentType() {
        if (!this.#workspaceContext)
            return;
        this.observe(this.#workspaceContext.allowedAtRoot, (allowedAtRoot) => (this._allowedAtRoot = allowedAtRoot), '_allowedAtRootObserver');
        this.observe(this.#workspaceContext.allowedContentTypes, (allowedContentTypes) => {
            const oldValue = this._allowedContentTypeUniques;
            this._allowedContentTypeUniques = allowedContentTypes
                ?.map((x) => x.contentType.unique)
                .filter((x) => x !== undefined);
            this.requestUpdate('_allowedContentTypeUniques', oldValue);
        }, '_allowedContentTypesObserver');
        this.observe(this.#workspaceContext.collection, (collection) => {
            this._collection = collection?.unique;
        }, '_collectionObserver');
    }
    render() {
        return html `
			<uui-box headline=${this.localize.term('contentTypeEditor_structure')}>
				<umb-property-layout alias="Root" label=${this.localize.term('contentTypeEditor_allowAtRootHeading')}>
					<div slot="description">${this.localize.term('contentTypeEditor_allowAtRootDescription')}</div>
					<div slot="editor">
						<uui-toggle
							label=${this.localize.term('contentTypeEditor_allowAtRootHeading')}
							?checked=${this._allowedAtRoot}
							@change=${(e) => {
            this.#workspaceContext?.setAllowedAtRoot(e.target.checked);
        }}></uui-toggle>
					</div>
				</umb-property-layout>
				<umb-property-layout alias="ChildNodeType" label=${this.localize.term('contentTypeEditor_childNodesHeading')}>
					<div slot="description">${this.localize.term('contentTypeEditor_childNodesDescription')}</div>
					<div slot="editor">
						<!-- TODO: maybe we want to somehow display the hierarchy, but not necessary in the same way as old backoffice? -->
						<umb-input-document-type
							.documentTypesOnly=${true}
							.selection=${this._allowedContentTypeUniques ?? []}
							@change="${(e) => {
            const sortedContentTypesList = e.target.selection.map((id, index) => ({
                contentType: { unique: id },
                sortOrder: index,
            }));
            this.#workspaceContext?.setAllowedContentTypes(sortedContentTypesList);
        }}">
						</umb-input-document-type>
					</div>
				</umb-property-layout>
			</uui-box>
			<uui-box headline=${this.localize.term('contentTypeEditor_presentation')}>
				<umb-property-layout alias="collection" label="${this.localize.term('contentTypeEditor_collection')}">
					<div slot="description">${this.localize.term('contentTypeEditor_collectionDescription')}</div>
					<div slot="editor">
						<umb-input-content-type-collection-configuration
							default-value="c0808dd3-8133-4e4b-8ce8-e2bea84a96a4"
							.value=${this._collection ?? undefined}
							@change=${(e) => {
            const unique = e.target.value;
            this.#workspaceContext?.setCollection({ unique });
        }}>
						</umb-input-content-type-collection-configuration>
					</div>
				</umb-property-layout>
			</uui-box>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: block;
				margin: var(--uui-size-layout-1);
				padding-bottom: var(--uui-size-layout-1); // To enforce some distance to the bottom of the scroll-container.
			}
			uui-box {
				margin-top: var(--uui-size-layout-1);
			}
			uui-label,
			umb-property-editor-ui-number {
				display: block;
			}

			// TODO: is this necessary?
			uui-toggle {
				display: flex;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewStructureElement.prototype, "_allowedAtRoot", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewStructureElement.prototype, "_allowedContentTypeUniques", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewStructureElement.prototype, "_collection", void 0);
UmbDocumentTypeWorkspaceViewStructureElement = __decorate([
    customElement('umb-document-type-workspace-view-structure')
], UmbDocumentTypeWorkspaceViewStructureElement);
export { UmbDocumentTypeWorkspaceViewStructureElement };
export default UmbDocumentTypeWorkspaceViewStructureElement;
