const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api

export class SpecialAbilitySheet extends HandlebarsApplicationMixin(DocumentSheetV2) {

    /** @inheritDoc */
    static DEFAULT_OPTIONS = {
        position: {width: 520, height: 480},
        classes: ['dsa41', 'sheet', 'item', 'specialability'],
        tag: 'form',
        form: {
            submitOnChange: true,
            closeOnSubmit: false,
            handler: SpecialAbilitySheet.#onSubmitForm
        },
    }


    static TABS = {
        sheet: {
            tabs: [
                {id: 'specialability', group: 'sheet', label: 'Sonderfertigkeit'},
            ],
            initial: 'specialability'
        }
    }

    /** @inheritDoc */
    static PARTS = {
        form: {
            template: `systems/DSA_4-1/templates/item/specialability/main-sheet.hbs`
        },
        specialability: {
            template: `systems/DSA_4-1/templates/item/specialability/tab-specialability.hbs`
        },
    }

    /**
     * Handle form submission
     * @this {EquipmentSheet}
     * @param {SubmitEvent} event
     * @param {HTMLFormElement} form
     * @param {FormDataExtended} formData
     */
    static async #onSubmitForm(event, form, formData) {
        event.preventDefault()

        await this.document.update(formData.object) // Note: formData.object
    }

    /** @override */
    async _prepareContext(options) {
        const context = await super._prepareContext(options);

        const specialabilityData = context.document;

        context.system = specialabilityData.system;
        context.flags = specialabilityData.flags;
        context.text = specialabilityData.system.text;
        context.aktionsText = specialabilityData.system.aktionsText;

        return context;
    }

}
