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 { UmbFolderModalElementBase } from './folder-modal-element-base.js';
import { customElement } from '../../../../../external/lit/index.js';
let UmbFolderModalElement = class UmbFolderModalElement extends UmbFolderModalElementBase {
    async init() {
        if (!this.folderRepository)
            throw new Error('A folder repository is required to load a folder');
        if (!this.data?.unique)
            throw new Error('A unique is required to load folder');
        const { data } = await this.folderRepository.requestByUnique(this.data.unique);
        if (data) {
            this.value = { folder: data };
        }
    }
    async onFormSubmit({ name }) {
        if (!this.folderRepository)
            throw new Error('A folder repository is required to update a folder');
        if (this.value.folder === undefined)
            throw new Error('The folder was not initialized correctly');
        const { data } = await this.folderRepository.save({
            ...this.value.folder,
            name,
        });
        if (data) {
            this.value = { folder: data };
            this._submitModal();
        }
    }
};
UmbFolderModalElement = __decorate([
    customElement('umb-folder-update-modal')
], UmbFolderModalElement);
export { UmbFolderModalElement };
export default UmbFolderModalElement;
