import { ItemSheetL5r5e } from "./item-sheet.js";

/**
 * @extends {ItemSheet}
 */
export class WeaponSheetL5r5e extends ItemSheetL5r5e {
    /** @override */
    static get defaultOptions() {
        return foundry.utils.mergeObject(super.defaultOptions, {
            classes: ["l5r5e", "sheet", "weapon"],
            template: CONFIG.l5r5e.paths.templates + "items/weapon/weapon-sheet.html",
        });
    }

    async getData(options = {}) {
        const sheetData = await super.getData(options);

        // Only these four skills are relevant for weapons
        const allowedSkills = ["archery", "unarmed", "melee", "invocation"];
        sheetData.data.skills = Array.from(CONFIG.l5r5e.skills)
            .filter(([id]) => allowedSkills.includes(id))
            .map(([id, cat]) => ({
                id,
                label: "l5r5e.skills." + cat.toLowerCase() + "." + id.toLowerCase(),
            }));

        // Weapon categories (Chiaroscuro) — sorted alphabetically
        const catObj = game.l5r5e.HelpersL5r5e.getLocalizedRawObject("chiaroscuro.weapon.categories") ?? {};
        sheetData.data.weaponCategories = [{ id: "", label: "—" }].concat(
            Object.entries(catObj)
                .map(([id, label]) => ({ id, label }))
                .sort((a, b) => a.label.localeCompare(b.label, undefined, { sensitivity: "base" }))
        );

        return sheetData;
    }
}
