export class AusruestungSheet extends foundry.appv1.sheets.ItemSheet {
    /**@override */
    static get defaultOptions() {
        return foundry.utils.mergeObject(super.defaultOptions, {
            classes: ['dsa41', 'sheet', 'item', 'equipment'],
            width: 520,
            height: 480,
            tabs: [
                {
                    navSelector: '.sheet-tabs',
                    contentSelector: '.sheet-body',
                    initial: 'description',
                },
            ],
        });
    }

    /** @override */
    get template() {
        return `systems/DSA_4-1/templates/item/item-equipment-sheet.hbs`;
    }

    /** @override */
    getData() {
        // Retrieve the data structure from the base sheet. You can inspect or log
        // the context variable to see the structure, but some key properties for
        // sheets are the actor object, the data object, whether or not it's
        // editable, the items array, and the effects array.
        const context = super.getData();

        // Use a safe clone of the actor data for further operations.
        const equipmentData = context.data;

        // Add the actor's data to context.data for easier access, as well as flags.
        context.system = equipmentData.system;
        context.flags = equipmentData.flags;

        context.quantity = context.system.quantity;
        context.description = context.system.description;

        context.categoryAndOptions = {
            options: {
                Gegenstand: "Gegenstand",
                Nahkampfwaffe: "Nahkampfwaffe",
                Fernkampfwaffe: "Fernkampfwaffe",
                Behälter: "Behälter",
                Rüstung: "Rüstung",
            },
            entries: context.system.category,
            targetField: "category"
        };
        context.isMeleeWeapon = context.system.category.includes("Nahkampfwaffe");
        context.isRangedWeapon = context.system.category.includes("Fernkampfwaffe");
        context.isContainer = context.system.category.includes("Behälter");
        context.isArmor = context.system.category.includes("Rüstung");
        context.price = context.system.price;
        context.weight = context.system.weight;
        context.meleeSkillsAndOptions = {
            options: {
                "": "",
                Dolche: "Dolche",
                Fechtwaffen: "Fechtwaffen",
                Säbel: "Säbel",
                Schwerter: "Schwerter",
                Anderthalbhänder: "Anderthalbhänder",
                "Zweihandschwerter/-säbel": "Zweihandschwerter/-säbel",
                "Infanteriewaffen": "Infanteriewaffen",
                "Speere": "Speere",
                "Stäbe": "Stäbe",
                "Hiebwaffen": "Hiebwaffen",
                "Zweihand-Hiebwaffen": "Zweihand-Hiebwaffen",
                "Kettenwaffen": "Kettenwaffen",
                "Raufen": "Raufen"
            },
            entries: context.system.meleeSkills,
            targetField: "meleeSkills"
        }
        context.rangedSkillsAndOptions = {
            options: {
                "": "",
                "Wurfmesser": "Wurfmesser",
                "Wurfspeer": "Wurfspeer",
                "Wurfbeil": "Wurfbeil",
                "Armbrust": "Armbrust",
                "Bogen": "Bogen",
            },
            entries: context.system.rangedSkills,
            targetField: "rangedSkills"
        }
        return context;
    }

    activateListeners(html) {
        super.activateListeners(html);

        html.on('change', '.array-editor select', (evt) => {
            const addingValue = evt.currentTarget.value;
            const fieldToTarget = evt.currentTarget.dataset.targetField;
            const newSkills = [...this.object.system[fieldToTarget], addingValue];

            this.object.update({system: {[fieldToTarget]: newSkills}});
            evt.currentTarget.value = "";
        })

    }

}
