import { TEMPLATE_DESCRIPTION, TEMPLATE_INVENTAIRE } from "../../common/_module.mjs";
import { ITEM_TYPES, ACTOR_TYPES } from "../../constants.js";
import { SystemCompendiums } from "../../settings/system-compendiums.js";
import RdDItemBaseSheet from "./common-item-sheet.mjs";

export default class RdDArmeSheet extends RdDItemBaseSheet {
  static get ITEM_TYPE() { return ITEM_TYPES.arme; }
  static get TEMPLATES() { return [TEMPLATE_DESCRIPTION, TEMPLATE_INVENTAIRE]; }

  static MORTALITE_CHOICES = {
    mortel: "Mortel",
    "non-mortel": "Non mortel",
    empoignade: "Empoignade",
  }

  static CATEGORIE_PARADE_CHOICES = {
    "sans-armes": "Sans arme",
    "armes-naturelles": "Armes naturelles",
    hast: "Armes d'hast",
    batons: "Bâtons",
    boucliers: "Boucliers",
    dagues: "Dagues",
    "epees-courtes": "Epées courtes",
    "epees-longues": "Epées longues",
    "epees-lourdes": "Epées lourdes",
    haches: "Haches",
    lances: "Lances",
    masses: "Masses",
  }

  static INIT_CHOICES = {
    hast: "Armes Hast",
    lance: "Lance",
    baton: "Bâton",
    doubledragonne: "Double Dragonne",
    esparlongue: "Esparlongue",
    epeedragonne: "Epée Dragonne",
    epeebatarde: "Epée Bâtarde",
    epeecyane: "Epée Cyane",
    epeesorde: "Epée Sorde",
    grandehache: "Grande Hache",
    hachebataille: "Hache de Bataille",
    epeegnome: "Epée Gnome",
    masse: "Masse",
    gourdin: "Gourdin",
    fleau: "Fléaux",
    dague: "Dague",
    armenaturelle: "Armes Naturelles",
    autre: "Autres",
  }

  static DEFAULT_OPTIONS = Object.assign({},
    RdDItemBaseSheet.DEFAULT_OPTIONS,
    {
      classes: ["fvtt-rdd", "item", "arme"],
      position: { width: 448 },
      window: { contentClasses: ["arme-content"] },
    });

  static PARTS = {
    main: {
      template: "systems/foundryvtt-reve-de-dragon/templates/sheets/item/arme.hbs",
    },
  };

  async _prepareContext() {
    const competences = (await SystemCompendiums.getCompetences(ACTOR_TYPES.personnage))
      .filter(it => it.isCompetenceArme())
    const competenceMeleeChoices = {}
    const competenceLancerChoices = {}
    const competenceTirChoices = {}
    competences.forEach(c => {
      const label = c.name
      switch (c.system.categorie) {
        case 'melee': competenceMeleeChoices[label] = label; break
        case 'lancer': competenceLancerChoices[label] = label; break
        case 'tir': competenceTirChoices[label] = label; break
      }
    })
    return Object.assign(
      await super._prepareContext(),
      {
        competenceMeleeChoices,
        competenceLancerChoices,
        competenceTirChoices,
        mortaliteChoices: RdDArmeSheet.MORTALITE_CHOICES,
        categorieParadeChoices: RdDArmeSheet.CATEGORIE_PARADE_CHOICES,
        initChoices: RdDArmeSheet.INIT_CHOICES,
      }
    );
  }
}
