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_PARTIAL_VIEW_FROM_SNIPPET_MODAL } from '../snippet-modal/index.js';
import { UMB_PARTIAL_VIEW_FOLDER_REPOSITORY_ALIAS } from '../../../constants.js';
import { html, customElement, css } from '../../../../../../external/lit/index.js';
import { UmbModalBaseElement, umbOpenModal } from '../../../../../core/modal/index.js';
import { UmbCreateFolderEntityAction } from '../../../../../core/tree/index.js';
let UmbPartialViewCreateOptionsModalElement = class UmbPartialViewCreateOptionsModalElement extends UmbModalBaseElement {
    #createFolderAction;
    connectedCallback() {
        super.connectedCallback();
        if (!this.data?.parent)
            throw new Error('A parent unique is required to create a folder');
        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_PARTIAL_VIEW_FOLDER_REPOSITORY_ALIAS,
            },
        });
    }
    async #onCreateFolderClick(event) {
        event.stopPropagation();
        await this.#createFolderAction
            ?.execute()
            .then(() => this._submitModal())
            .catch(() => undefined);
    }
    async #onCreateFromSnippetClick(event) {
        event.stopPropagation();
        if (!this.data?.parent)
            throw new Error('A parent is required to create a folder');
        umbOpenModal(this, UMB_PARTIAL_VIEW_FROM_SNIPPET_MODAL, {
            data: {
                parent: this.data.parent,
            },
        })
            .then(() => this._submitModal())
            .catch(() => undefined);
    }
    // close the modal when navigating to data type
    #onNavigate() {
        this._submitModal();
    }
    #getCreateHref() {
        return `section/settings/workspace/partial-view/create/parent/${this.data?.parent.entityType}/${this.data?.parent.unique || 'null'}`;
    }
    render() {
        return html `
			<uui-dialog-layout headline=${this.localize.term('general_create')}>
				<!-- TODO: construct url -->
				<uui-menu-item
					href=${this.#getCreateHref()}
					label=${this.localize.term('create_newEmptyPartialView')}
					@click=${this.#onNavigate}>
					<uui-icon slot="icon" name="icon-document-html"></uui-icon>
				</uui-menu-item>

				<uui-menu-item
					@click=${this.#onCreateFromSnippetClick}
					label="${this.localize.term('create_newPartialViewFromSnippet')}...">
					<uui-icon slot="icon" name="icon-document-html"></uui-icon>
				</uui-menu-item>

				<uui-menu-item @click=${this.#onCreateFolderClick} label="${this.localize.term('create_newFolder')}...">
					<uui-icon slot="icon" name="icon-folder"></uui-icon>
				</uui-menu-item>

				<uui-button
					slot="actions"
					id="cancel"
					label=${this.localize.term('buttons_confirmActionCancel')}
					@click="${this._rejectModal}"></uui-button>
			</uui-dialog-layout>
		`;
    }
    static { this.styles = [
        css `
			uui-dialog-layout {
				--uui-menu-item-flat-structure: 1;
			}
		`,
    ]; }
};
UmbPartialViewCreateOptionsModalElement = __decorate([
    customElement('umb-partial-view-create-options-modal')
], UmbPartialViewCreateOptionsModalElement);
export { UmbPartialViewCreateOptionsModalElement };
export default UmbPartialViewCreateOptionsModalElement;
