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_BLOCK_WORKSPACE_CONTEXT } from '../../block-workspace.context-token.js';
import { css, html, customElement, property, state, repeat } from '../../../../../../external/lit/index.js';
import { UmbTextStyles } from '../../../../../core/style/index.js';
import { UmbContentTypeContainerStructureHelper } from '../../../../../content/content-type/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import './block-workspace-view-edit-properties.element.js';
let UmbBlockWorkspaceViewEditTabElement = class UmbBlockWorkspaceViewEditTabElement extends UmbLitElement {
    get managerName() {
        return this.#managerName;
    }
    set managerName(value) {
        this.#managerName = value;
        this.#setStructureManager();
    }
    #managerName;
    #blockWorkspace;
    #groupStructureHelper;
    get containerId() {
        return this._containerId;
    }
    set containerId(value) {
        this._containerId = value;
        this.#groupStructureHelper.setContainerId(value);
    }
    constructor() {
        super();
        this.#groupStructureHelper = new UmbContentTypeContainerStructureHelper(this);
        /**
         * If true, the group box will be hidden, if we are to only represents one group.
         * This is used by Inline Editing Mode of Block List Editor.
         */
        this.hideSingleGroup = false;
        this._groups = [];
        this._hasProperties = false;
        this.consumeContext(UMB_BLOCK_WORKSPACE_CONTEXT, (workspaceContext) => {
            this.#blockWorkspace = workspaceContext;
            this.#setStructureManager();
        });
    }
    #setStructureManager() {
        if (!this.#blockWorkspace || !this.#managerName)
            return;
        this.#groupStructureHelper.setStructureManager(this.#blockWorkspace[this.#managerName].structure);
        this.observe(this.#groupStructureHelper.childContainers, (groups) => {
            this._groups = groups;
        }, 'observeGroups');
        this.observe(this.#groupStructureHelper.hasProperties, (hasProperties) => {
            this._hasProperties = hasProperties;
        }, 'observeHasProperties');
    }
    render() {
        return html `
			${this._hasProperties
            ? html `<uui-box>
						<umb-block-workspace-view-edit-properties
							.managerName=${this.#managerName}
							data-mark="property-group:root"
							.containerId=${this._containerId}></umb-block-workspace-view-edit-properties>
					</uui-box>`
            : ''}
			${this.hideSingleGroup && this._groups.length === 1
            ? this.renderGroup(this._groups[0])
            : repeat(this._groups, (group) => group.key, (group) => html `<uui-box .headline=${this.localize.string(group.name)}>${this.renderGroup(group)}</uui-box>`)}
		`;
    }
    renderGroup(group) {
        return html `
			<umb-block-workspace-view-edit-properties
				.managerName=${this.#managerName}
				data-mark="property-group:${group.name}"
				.containerId=${group.ids[0]}></umb-block-workspace-view-edit-properties>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			uui-box {
				--uui-box-default-padding: 0 var(--uui-size-space-5);
			}
			uui-box:not(:first-child) {
				margin-top: var(--uui-size-layout-1);
			}
		`,
    ]; }
};
__decorate([
    property({ attribute: false })
], UmbBlockWorkspaceViewEditTabElement.prototype, "managerName", null);
__decorate([
    property({ type: String })
], UmbBlockWorkspaceViewEditTabElement.prototype, "containerId", null);
__decorate([
    state()
], UmbBlockWorkspaceViewEditTabElement.prototype, "_containerId", void 0);
__decorate([
    property({ type: Boolean, reflect: false })
], UmbBlockWorkspaceViewEditTabElement.prototype, "hideSingleGroup", void 0);
__decorate([
    state()
], UmbBlockWorkspaceViewEditTabElement.prototype, "_groups", void 0);
__decorate([
    state()
], UmbBlockWorkspaceViewEditTabElement.prototype, "_hasProperties", void 0);
UmbBlockWorkspaceViewEditTabElement = __decorate([
    customElement('umb-block-workspace-view-edit-tab')
], UmbBlockWorkspaceViewEditTabElement);
export { UmbBlockWorkspaceViewEditTabElement };
export default UmbBlockWorkspaceViewEditTabElement;
