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 { css, html, state } from '../../../../../external/lit/index.js';
import { UmbTextStyles } from '../../../style/index.js';
import { UmbModalBaseElement } from '../../../modal/index.js';
import { UmbExtensionApiInitializer } from '../../../../../libs/extension-api/index.js';
import { umbExtensionsRegistry } from '../../../extension-registry/index.js';
import { umbFocus } from '../../../lit-element/index.js';
export class UmbFolderModalElementBase extends UmbModalBaseElement {
    constructor() {
        super(...arguments);
        this._isNew = false;
    }
    connectedCallback() {
        super.connectedCallback();
        this.#observeRepository();
    }
    #observeRepository() {
        if (!this.data?.folderRepositoryAlias)
            throw new Error('A folder repository alias is required');
        new UmbExtensionApiInitializer(this, umbExtensionsRegistry, this.data.folderRepositoryAlias, [this], (permitted, ctrl) => {
            this.folderRepository = permitted ? ctrl.api : undefined;
            if (this.folderRepository) {
                this.init();
            }
        });
    }
    async #onSubmit(event) {
        event.preventDefault();
        const form = event.target;
        if (!form)
            return;
        const isValid = form.checkValidity();
        if (!isValid)
            return;
        const formData = new FormData(form);
        const name = formData.get('name');
        this.onFormSubmit({ name });
    }
    render() {
        return html `
			<umb-body-layout headline=${this.localize.term(this._isNew ? 'actions_folderCreate' : 'actions_folderRename')}>
				<uui-box>
					<uui-form>
						<form id="FolderForm" @submit="${this.#onSubmit}">
							<uui-form-layout-item>
								<uui-label id="nameLabel" for="name" slot="label" required>
									<umb-localize key="create_enterFolderName">Enter folder name</umb-localize>
								</uui-label>
								<uui-input
									type="text"
									id="name"
									name="name"
									.label=${this.localize.term('create_enterFolderName')}
									.value="${this.value?.folder?.name || ''}"
									required
									${umbFocus()}></uui-input>
							</uui-form-layout-item>
						</form>
					</uui-form>
				</uui-box>

				<uui-button
					slot="actions"
					id="cancel"
					label=${this.localize.term('buttons_confirmActionCancel')}
					@click="${this._rejectModal}"></uui-button>
				<uui-button
					form="FolderForm"
					type="submit"
					slot="actions"
					id="confirm"
					color="positive"
					look="primary"
					label=${this.localize.term(this._isNew ? 'actions_folderCreate' : 'actions_folderRename')}></uui-button>
			</umb-body-layout>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			#name {
				width: 100%;
			}
		`,
    ]; }
}
__decorate([
    state()
], UmbFolderModalElementBase.prototype, "_isNew", void 0);
