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_BLUEPRINT_FOLDER_REPOSITORY_ALIAS, UmbDocumentBlueprintFolderRepository, } from '../../../tree/index.js';
import { UmbTextStyles } from '../../../../../core/style/index.js';
import { html, customElement, css, state } from '../../../../../../external/lit/index.js';
import { UmbModalBaseElement, umbOpenModal } from '../../../../../core/modal/index.js';
import { UmbSelectionChangeEvent } from '../../../../../core/event/index.js';
import { UmbCreateFolderEntityAction } from '../../../../../core/tree/index.js';
import { UMB_DOCUMENT_TYPE_PICKER_MODAL, } from '../../../../document-types/index.js';
let UmbDocumentBlueprintOptionsCreateModalElement = class UmbDocumentBlueprintOptionsCreateModalElement extends UmbModalBaseElement {
    #createFolderAction;
    #folderRepository = new UmbDocumentBlueprintFolderRepository(this);
    async connectedCallback() {
        super.connectedCallback();
        if (!this.data?.parent)
            throw new Error('A parent is required to create a folder');
        if (this.data.parent.unique) {
            const { data: parent } = await this.#folderRepository.requestByUnique(this.data.parent.unique.toString());
            this._parentName = parent?.name ?? this.localize.term('general_unknown');
        }
        else {
            this._parentName = this.localize.term('treeHeaders_contentBlueprints');
        }
        // TODO: render the info from this instance in the list of actions
        this.#createFolderAction = new UmbCreateFolderEntityAction(this, {
            unique: this.data.parent.unique,
            entityType: this.data.parent.entityType,
            meta: {
                icon: 'icon-folder',
                label: this.localize.term('create_newFolder'),
                folderRepositoryAlias: UMB_DOCUMENT_BLUEPRINT_FOLDER_REPOSITORY_ALIAS,
            },
        });
    }
    async #onCreateFolderClick(event) {
        event.stopPropagation();
        this.#createFolderAction
            ?.execute()
            .then(() => {
            this._submitModal();
        })
            .catch(() => { });
    }
    async #onCreateBlueprintClick(event) {
        event.stopPropagation();
        const value = await umbOpenModal(this, UMB_DOCUMENT_TYPE_PICKER_MODAL, {
            data: {
                hideTreeRoot: true,
                pickableFilter: (item) => item.isElement == false,
            },
        });
        const selection = value.selection.filter((x) => x !== null);
        this.value = { documentTypeUnique: selection[0] };
        this.modalContext?.dispatchEvent(new UmbSelectionChangeEvent());
        this._submitModal();
    }
    render() {
        return html `
			<uui-dialog-layout headline=${this.localize.term('general_create')}>
				<uui-ref-list>
					<umb-ref-item
						name="Document Blueprint for..."
						icon="icon-blueprint"
						@open=${this.#onCreateBlueprintClick}></umb-ref-item>

					<umb-ref-item
						name=${this.localize.term('create_newFolder') + '...'}
						icon="icon-folder"
						@open=${this.#onCreateFolderClick}></umb-ref-item>
				</uui-ref-list>

				<uui-button
					slot="actions"
					id="cancel"
					label=${this.localize.term('buttons_confirmActionCancel')}
					@click="${this._rejectModal}"></uui-button>
			</uui-dialog-layout>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			uui-box:first-child {
				margin-bottom: var(--uui-size-6);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbDocumentBlueprintOptionsCreateModalElement.prototype, "_parentName", void 0);
UmbDocumentBlueprintOptionsCreateModalElement = __decorate([
    customElement('umb-document-blueprint-options-create-modal')
], UmbDocumentBlueprintOptionsCreateModalElement);
export { UmbDocumentBlueprintOptionsCreateModalElement };
export default UmbDocumentBlueprintOptionsCreateModalElement;
