import MournbladeCYD2ActorSheetV2 from "./base-actor-sheet.mjs";
import { MournbladeCYD2Utility } from "../../mournblade-cyd2-utility.js";

export default class MournbladeCYD2PersonnageSheet extends MournbladeCYD2ActorSheetV2 {

  /** @override */
  static DEFAULT_OPTIONS = {
    ...super.DEFAULT_OPTIONS,
    classes: [...super.DEFAULT_OPTIONS.classes],
    window: {
      ...super.DEFAULT_OPTIONS.window,
      title: "SHEETS.Actor.personnage",
    },
  };

  /** @override */
  static PARTS = {
    sheet: {
      template: "systems/fvtt-mournblade-cyd-2-0/templates/actor-sheet.hbs",
    },
  };

  /** @override */
  tabGroups = { primary: "principal" };

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

    context.combativiteList = MournbladeCYD2Utility.getCombativiteList(actor.system.sante.nbcombativite);
    context.ameList = MournbladeCYD2Utility.getAmeList(actor.system.ame.nbame, actor.getAmeMax?.() ?? 0);
    context.ameMaxList = MournbladeCYD2Utility.getAmeMaxList(actor.system.ame.nbame);

    context.skills = actor.getSkills?.() ?? [];
    context.armes = foundry.utils.duplicate(actor.getWeapons?.() ?? []);
    context.protections = foundry.utils.duplicate(actor.getArmors?.() ?? []);
    context.dons = foundry.utils.duplicate(actor.getDons?.() ?? []);
    context.pactes = foundry.utils.duplicate(actor.getPactes?.() ?? []);
    context.tendances = foundry.utils.duplicate(actor.getTendances?.() ?? []);
    context.runes = foundry.utils.duplicate(actor.getRunes?.() ?? []);
    context.traitsChaotiques = foundry.utils.duplicate(actor.getTraitsChaotiques?.() ?? []);
    context.traitsEspeces = foundry.utils.duplicate(actor.getTraitsEspeces?.() ?? []);
    context.profil = actor.getProfil?.() ?? null;
    context.historiques = foundry.utils.duplicate(actor.getHistoriques?.() ?? []);
    context.combat = actor.getCombatValues?.() ?? {};
    context.equipements = foundry.utils.duplicate(actor.getEquipments?.() ?? []);
    context.monnaies = foundry.utils.duplicate(actor.getMonnaies?.() ?? []);
    context.runeEffects = foundry.utils.duplicate(actor.getRuneEffects?.() ?? []);
    context.ressources = foundry.utils.duplicate(actor.getRessources?.() ?? []);
    context.talents = foundry.utils.duplicate(actor.getTalents?.() ?? []);
    context.protectionTotal = actor.getProtectionTotal?.() ?? 0;
    context.adversiteTotal = (actor.system.adversite?.bleue || 0) + (actor.system.adversite?.rouge || 0) + (actor.system.adversite?.noire || 0);
    return context;
  }
}
