/**
 * Donjon & Cie - Systeme FoundryVTT
 *
 * Donjon & Cie est un jeu de role edite par John Doe.
 * Ce systeme FoundryVTT est une implementation independante et n'est pas
 * affilie a John Doe.
 *
 * @author    LeRatierBretonnien
 * @copyright 2025–2026 LeRatierBretonnien
 * @license   CC BY-NC-SA 4.0 – https://creativecommons.org/licenses/by-nc-sa/4.0/
 */

import DonjonEtCieActorSheet from "./base-actor-sheet.mjs";
import { DonjonEtCieUtility } from "../../donjon-et-cie-utility.mjs";

export default class DonjonEtCieEmployeSheet extends DonjonEtCieActorSheet {
  static DEFAULT_OPTIONS = {
    ...super.DEFAULT_OPTIONS,
    classes: [...super.DEFAULT_OPTIONS.classes, "employe"],
    position: { width: 980, height: 860 }
  };

  static PARTS = {
    main: { template: "systems/fvtt-donjon-et-cie/templates/actors/employe-sheet.hbs" }
  };

  async _prepareContext() {
    const context = await super._prepareContext();
    const indexedSections = Object.fromEntries(context.sections.map((section) => [section.key, section]));
    const getSection = (key) => indexedSections[key] ?? {
      key,
      label: context.config.actorSections[key]?.label ?? key,
      createType: context.config.actorSections[key]?.createType ?? key,
      items: []
    };

    return {
      ...context,
      magicResources: DonjonEtCieUtility.getMagicResourceContext(this.document),
      favorEntries: this.document.getFavorEntries(),
      chaosTable: DonjonEtCieUtility.getChaosTableEntries(),
      traitsSection: getSection("traits"),
      combatSections: ["armes", "armures", "consommables", "equipements"].map(getSection),
      spellSection: getSection("sortileges"),
      capacitySection: getSection("capacites"),
      profileSections: ["langues", "entrainements"].map(getSection)
    };
  }
}
