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 { html, customElement, property, state, nothing } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import { UmbDataPathPropertyValueQuery } from '../../../../../core/validation/index.js';
import { UmbVariantId } from '../../../../../core/variant/index.js';
let UmbBlockWorkspaceViewEditPropertyElement = class UmbBlockWorkspaceViewEditPropertyElement extends UmbLitElement {
    willUpdate(changedProperties) {
        super.willUpdate(changedProperties);
        if (changedProperties.has('type') || changedProperties.has('variantId') || changedProperties.has('ownerContext')) {
            if (this.variantId && this.property && this.ownerContext) {
                const propertyVariantId = new UmbVariantId(this.property.variesByCulture ? this.variantId.culture : null, this.property.variesBySegment ? this.variantId.segment : null);
                this._dataPath = `$.values[${UmbDataPathPropertyValueQuery({
                    alias: this.property.alias,
                    culture: propertyVariantId.culture,
                    segment: propertyVariantId.segment,
                })}].value`;
                this.observe(this.ownerContext.propertyWriteGuard.isPermittedForVariantAndProperty(propertyVariantId, this.property, this.variantId), (write) => {
                    this._writeable = write;
                }, 'observeView');
            }
        }
        if (changedProperties.has('property') || changedProperties.has('ownerContext')) {
            const dataTypeUnique = this.property?.dataType.unique;
            if (dataTypeUnique && this.ownerContext) {
                this.observe(this.ownerContext.structure.contentTypeDataTypeDetailOf(dataTypeUnique), (detail) => {
                    this._dataTypeDetail = detail;
                }, 'observeDataTypeDetail');
            }
        }
    }
    render() {
        if (!this._dataPath || this._writeable === undefined)
            return nothing;
        return html `<umb-property-type-based-property
			data-path=${this._dataPath}
			.property=${this.property}
			.dataTypeDetail=${this._dataTypeDetail}
			?readonly=${!this._writeable}></umb-property-type-based-property>`;
    }
};
__decorate([
    property({ attribute: false })
], UmbBlockWorkspaceViewEditPropertyElement.prototype, "variantId", void 0);
__decorate([
    property({ attribute: false })
], UmbBlockWorkspaceViewEditPropertyElement.prototype, "property", void 0);
__decorate([
    state()
], UmbBlockWorkspaceViewEditPropertyElement.prototype, "_dataPath", void 0);
__decorate([
    state()
], UmbBlockWorkspaceViewEditPropertyElement.prototype, "_writeable", void 0);
__decorate([
    state()
], UmbBlockWorkspaceViewEditPropertyElement.prototype, "_dataTypeDetail", void 0);
__decorate([
    property({ attribute: false })
], UmbBlockWorkspaceViewEditPropertyElement.prototype, "ownerContext", void 0);
UmbBlockWorkspaceViewEditPropertyElement = __decorate([
    customElement('umb-block-workspace-view-edit-property')
], UmbBlockWorkspaceViewEditPropertyElement);
export { UmbBlockWorkspaceViewEditPropertyElement };
export default UmbBlockWorkspaceViewEditPropertyElement;
