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_DATA_TYPE_WORKSPACE_CONTEXT } from '../../data-type-workspace.context-token.js';
import { css, customElement, html, nothing, state } from '../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../core/lit-element/index.js';
import { UMB_MISSING_PROPERTY_EDITOR_UI_ALIAS } from '../../../../core/property-editor/index.js';
import { UmbTextStyles } from '../../../../core/style/index.js';
import { umbBindToValidation } from '../../../../core/validation/index.js';
import { umbExtensionsRegistry } from '../../../../core/extension-registry/index.js';
let UmbDataTypeDetailsWorkspaceViewEditElement = class UmbDataTypeDetailsWorkspaceViewEditElement extends UmbLitElement {
    #workspaceContext;
    constructor() {
        super();
        this._propertyEditorDataSourceAlias = null;
        this._supportsDataSource = false;
        this._supportedDataSourceTypes = [];
        this.consumeContext(UMB_DATA_TYPE_WORKSPACE_CONTEXT, (workspaceContext) => {
            this.#workspaceContext = workspaceContext;
            this.#observeDataType();
        });
    }
    #observeDataType() {
        if (!this.#workspaceContext) {
            return;
        }
        this.observe(this.#workspaceContext.propertyEditorUiAlias, (value) => {
            this._propertyEditorUiAlias = value ?? undefined;
            this.#observePropertyEditorUIManifest();
        });
        this.observe(this.#workspaceContext.propertyEditorSchemaAlias, (value) => {
            this._propertyEditorSchemaAlias = value ?? undefined;
        });
        this.observe(this.#workspaceContext.propertyEditorUiName, (value) => {
            this._propertyEditorUiName = value ?? undefined;
        });
        this.observe(this.#workspaceContext.propertyEditorUiIcon, (value) => {
            this._propertyEditorUiIcon = value ?? undefined;
        });
        this.observe(this.#workspaceContext.propertyEditorDataSourceAlias, (value) => {
            this._propertyEditorDataSourceAlias = value;
        });
    }
    #observePropertyEditorUIManifest() {
        if (!this._propertyEditorUiAlias)
            return;
        this.observe(umbExtensionsRegistry.byTypeAndAlias('propertyEditorUi', this._propertyEditorUiAlias), (manifest) => {
            this._supportsDataSource = manifest?.meta?.supportsDataSource?.enabled ?? false;
            this._supportedDataSourceTypes = manifest?.meta?.supportsDataSource?.forDataSourceTypes ?? [];
        });
    }
    #onDataSourceChange(event) {
        const value = event.target.value;
        this.#workspaceContext?.setPropertyEditorDataSourceAlias(value || undefined);
    }
    render() {
        return html `
			<uui-box>
				<umb-property-layout
					data-mark="property:editorUiAlias"
					label="Property Editor"
					description=${this.localize.term('propertyEditorPicker_title')}
					mandatory>
					<umb-data-type-details-workspace-property-editor-picker
						slot="editor"
						.propertyEditorUiName=${this._propertyEditorUiName}
						.propertyEditorUiAlias=${this._propertyEditorUiAlias}
						.propertyEditorUiIcon=${this._propertyEditorUiIcon}
						.propertyEditorSchemaAlias=${this._propertyEditorSchemaAlias}
						${umbBindToValidation(this, '$.editorUiAlias', this._propertyEditorUiAlias)}>
					</umb-data-type-details-workspace-property-editor-picker>
				</umb-property-layout>
				${this.#renderDataSourceInput()}
			</uui-box>
			${this.#renderSettings()}
		`;
    }
    #renderDataSourceInput() {
        if (!this._supportsDataSource)
            return nothing;
        return html `
			<umb-property-layout label="Data Source" mandatory>
				<umb-input-property-editor-data-source
					.value=${this._propertyEditorDataSourceAlias || ''}
					.dataSourceTypes=${this._supportedDataSourceTypes}
					slot="editor"
					max="1"
					@change=${this.#onDataSourceChange}
					required
					${umbBindToValidation(this, '$.editorDataSourceAlias', this._propertyEditorDataSourceAlias)}></umb-input-property-editor-data-source>
			</umb-property-layout>
		`;
    }
    #renderSettings() {
        if (!this._propertyEditorUiAlias ||
            !this._propertyEditorUiName ||
            !this._propertyEditorSchemaAlias ||
            this._propertyEditorUiAlias === UMB_MISSING_PROPERTY_EDITOR_UI_ALIAS) {
            return nothing;
        }
        return html ` <uui-box headline=${this.localize.term('general_settings')}>
			<umb-property-editor-config></umb-property-editor-config>
		</uui-box>`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: block;
				margin: var(--uui-size-layout-1);
				padding-bottom: var(--uui-size-layout-1);
			}

			uui-box {
				margin-top: var(--uui-size-layout-1);
			}

			#btn-add {
				display: block;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_propertyEditorUiIcon", void 0);
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_propertyEditorUiName", void 0);
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_propertyEditorUiAlias", void 0);
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_propertyEditorSchemaAlias", void 0);
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_propertyEditorDataSourceAlias", void 0);
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_supportsDataSource", void 0);
__decorate([
    state()
], UmbDataTypeDetailsWorkspaceViewEditElement.prototype, "_supportedDataSourceTypes", void 0);
UmbDataTypeDetailsWorkspaceViewEditElement = __decorate([
    customElement('umb-data-type-details-workspace-view')
], UmbDataTypeDetailsWorkspaceViewEditElement);
export { UmbDataTypeDetailsWorkspaceViewEditElement };
export default UmbDataTypeDetailsWorkspaceViewEditElement;
