import WastelandActorSheet from "./base-actor-sheet.mjs"

export default class WastelandPersonnageSheet extends WastelandActorSheet {
  /** @override */
  static DEFAULT_OPTIONS = {
    ...super.DEFAULT_OPTIONS,
    classes: [...super.DEFAULT_OPTIONS.classes, "personnage"],
    window: {
      ...super.DEFAULT_OPTIONS.window,
      title: "Feuille de Personnage",
    },
  }

  /** @override */
  static PARTS = {
    sheet: {
      template: "systems/fvtt-wasteland/templates/actor-personnage-sheet.hbs",
    },
  }

  /** @override */
  tabGroups = {
    primary: "stats",
  }

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

    // Add personnage-specific data
    context.skills = actor.getSkills()
    context.armes = foundry.utils.duplicate(actor.getWeapons())
    context.protections = foundry.utils.duplicate(actor.getArmors())
    context.pouvoirs = foundry.utils.duplicate(actor.getPouvoirs())
    context.dons = foundry.utils.duplicate(actor.getDons())
    context.hubrises = foundry.utils.duplicate(actor.getHubris())
    context.tours = foundry.utils.duplicate(actor.getTours())
    context.artifex = foundry.utils.duplicate(actor.getArtifex())
    context.charmes = foundry.utils.duplicate(actor.getCharmes())
    context.peuple = foundry.utils.duplicate(actor.getPeuple() || {})
    context.origine = foundry.utils.duplicate(actor.getOrigine() || {})
    context.heritage = foundry.utils.duplicate(actor.getHeritage() || {})
    context.metier = foundry.utils.duplicate(actor.getMetier() || {})
    context.combat = actor.getCombatValues()
    context.capacites = foundry.utils.duplicate(actor.getCapacites())
    context.equipements = foundry.utils.duplicate(actor.getEquipments())
    context.monnaies = foundry.utils.duplicate(actor.getMonnaies())
    context.mutations = foundry.utils.duplicate(actor.getMutations())

    // Enrich HTML fields for biodata
    context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(actor.system.biodata?.notes || "", { async: true })
    context.enrichedGMNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(actor.system.biodata?.gmnotes || "", { async: true })
    context.enrichedSequelles = await foundry.applications.ux.TextEditor.implementation.enrichHTML(actor.system.biodata?.sequelles || "", { async: true })
    context.enrichedTraumatismes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(actor.system.biodata?.traumatismes || "", { async: true })

    return context
  }
}
