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, css, state, nothing } from '../../../../../external/lit/index.js';
import { UmbChangeEvent } from '../../../../core/event/index.js';
import { UmbLitElement } from '../../../../core/lit-element/index.js';
import { UMB_DATATYPE_WORKSPACE_MODAL, UMB_DATA_TYPE_ENTITY_TYPE, UMB_DATA_TYPE_PICKER_FLOW_DATA_TYPE_PICKER_MODAL, } from '../../../../data-type/index.js';
import { UmbModalRouteRegistrationController } from '../../../../core/router/index.js';
import { UmbFormControlMixin } from '../../../../core/validation/index.js';
let UmbInputContentTypeCollectionConfigurationElement = class UmbInputContentTypeCollectionConfigurationElement extends UmbFormControlMixin(UmbLitElement) {
    getFormElement() {
        return undefined;
    }
    #dataTypeModal;
    #propertyEditorUiAlias = 'Umb.PropertyEditorUi.Collection';
    #setValue(value) {
        this.value = value;
        this.dispatchEvent(new UmbChangeEvent());
    }
    constructor() {
        super();
        new UmbModalRouteRegistrationController(this, UMB_DATA_TYPE_PICKER_FLOW_DATA_TYPE_PICKER_MODAL)
            .addAdditionalPath(':uiAlias')
            .onSetup((routingInfo) => {
            return {
                data: {
                    propertyEditorUiAlias: routingInfo.uiAlias,
                },
                value: undefined,
            };
        })
            .onSubmit((submitData) => {
            if (submitData?.createNewWithPropertyEditorUiAlias) {
                this.#createDataType();
            }
            else {
                this.#setValue(submitData?.dataTypeId ?? this.defaultValue ?? '');
            }
        })
            .observeRouteBuilder((routeBuilder) => {
            this._dataTypePickerModalPath = routeBuilder({ uiAlias: this.#propertyEditorUiAlias });
        });
        this.#dataTypeModal = new UmbModalRouteRegistrationController(this, UMB_DATATYPE_WORKSPACE_MODAL)
            .addAdditionalPath(':uiAlias')
            .onSetup((params) => {
            return { data: { entityType: UMB_DATA_TYPE_ENTITY_TYPE, preset: { editorUiAlias: params.uiAlias } } };
        })
            .onSubmit((value) => {
            this.#setValue(value?.unique ?? this.defaultValue ?? '');
        });
    }
    #clearDataType() {
        this.#setValue(undefined);
    }
    #createDataType() {
        this.#dataTypeModal.open({ uiAlias: this.#propertyEditorUiAlias }, `create/parent/${UMB_DATA_TYPE_ENTITY_TYPE}/null`);
    }
    #editDataType() {
        this.#dataTypeModal?.open({}, `edit/${this.value}`);
    }
    render() {
        return !this.value ? this.#renderCreate() : this.#renderConfigured();
    }
    #renderCreate() {
        if (!this._dataTypePickerModalPath)
            return nothing;
        return html `
			<uui-button
				id="create-button"
				color="default"
				look="placeholder"
				label=${this.localize.term('collection_addCollectionConfiguration')}
				href=${this._dataTypePickerModalPath}></uui-button>
		`;
    }
    #renderConfigured() {
        if (!this.value || !this._dataTypePickerModalPath)
            return nothing;
        return html `
			<uui-ref-list>
				<umb-ref-data-type standalone data-type-id=${this.value} @open=${this.#editDataType}>
					<uui-action-bar slot="actions">
						<uui-button
							label=${this.localize.term('general_choose')}
							href=${this._dataTypePickerModalPath}></uui-button>
						<uui-button @click=${this.#clearDataType} label=${this.localize.term('general_remove')}></uui-button>
					</uui-action-bar>
				</umb-ref-data-type>
			</uui-ref-list>
		`;
    }
    static { this.styles = [
        css `
			#create-button {
				width: 100%;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbInputContentTypeCollectionConfigurationElement.prototype, "_dataTypePickerModalPath", void 0);
__decorate([
    property({ attribute: 'default-value' })
], UmbInputContentTypeCollectionConfigurationElement.prototype, "defaultValue", void 0);
UmbInputContentTypeCollectionConfigurationElement = __decorate([
    customElement('umb-input-content-type-collection-configuration')
], UmbInputContentTypeCollectionConfigurationElement);
export { UmbInputContentTypeCollectionConfigurationElement };
