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_SCRIPT_FOLDER_REPOSITORY_ALIAS } from '../../../tree/folder/index.js';
import { html, customElement } from '../../../../../../external/lit/index.js';
import { UmbModalBaseElement } from '../../../../../core/modal/index.js';
import { UmbCreateFolderEntityAction } from '../../../../../core/tree/index.js';
let UmbScriptCreateOptionsModalElement = class UmbScriptCreateOptionsModalElement extends UmbModalBaseElement {
    #createFolderAction;
    connectedCallback() {
        super.connectedCallback();
        if (!this.data?.parent)
            throw new Error('A parent 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: 'New folder...',
                folderRepositoryAlias: UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS,
            },
        });
    }
    async #onCreateFolderClick(event) {
        event.stopPropagation();
        this.#createFolderAction
            ?.execute()
            .then(() => {
            this._submitModal();
        })
            .catch(() => { });
    }
    // close the modal when navigating to data type
    #onNavigate() {
        this._submitModal();
    }
    #getCreateHref() {
        return `section/settings/workspace/script/create/parent/${this.data?.parent.entityType}/${this.data?.parent.unique || 'null'}`;
    }
    render() {
        return html `
			<uui-dialog-layout headline=${this.localize.term('general_create')}>
				<uui-ref-list>
					<!-- TODO: construct url -->
					<umb-ref-item
						name="Javascript file"
						icon="icon-document-js"
						href=${this.#getCreateHref()}
						@click=${this.#onNavigate}>
					</umb-ref-item>

					<umb-ref-item name="Folder..." icon="icon-folder" @open=${this.#onCreateFolderClick}></umb-ref-item>
				</uui-ref-list>

				<uui-button slot="actions" id="cancel" label="Cancel" @click="${this._rejectModal}"></uui-button>
			</uui-dialog-layout>
		`;
    }
};
UmbScriptCreateOptionsModalElement = __decorate([
    customElement('umb-script-create-options-modal')
], UmbScriptCreateOptionsModalElement);
export { UmbScriptCreateOptionsModalElement };
export default UmbScriptCreateOptionsModalElement;
