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

export class ProfessionSheet extends HandlebarsApplicationMixin(DocumentSheetV2) {

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

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

    /**
     * Handle form submission
     * @this {ProfessionSheet}
     * @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)
        context.system = context.document.system

        context.name = context.document.name
        context.img = context.document.img
        context.description = context.document.system.description
        context.alias = context.document.system.alias
        context.isOwner = context.document.owner
        context.revealed = context.document.system.revealed

        return context
    }
}