import CelestopolItemSheet from "./base-item-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"

export class CelestopolAnomalySheet extends CelestopolItemSheet {
  static DEFAULT_OPTIONS = {
    classes: ["anomaly"],
    position: { width: 560, height: 560 },
  }
  static PARTS = {
    main: { template: "systems/fvtt-celestopol/templates/anomaly.hbs" },
  }
  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.anomalyTypes = SYSTEM.ANOMALY_TYPES

    const def = SYSTEM.ANOMALY_DEFINITIONS[ctx.system.subtype] ?? SYSTEM.ANOMALY_DEFINITIONS.none
    ctx.applicableSkillLabels = def.technicalSkills.map(key => {
      if (key === "lune") return game.i18n.localize("CELESTOPOL.Anomaly.moonDie")
      for (const skills of Object.values(SYSTEM.SKILLS)) {
        if (skills[key]) return game.i18n.localize(skills[key].label)
      }
      return key
    })

    ctx.enrichedTechnique = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.technique, { async: true })
    ctx.enrichedNarratif = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.narratif, { async: true })
    ctx.enrichedExemples = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.exemples, { async: true })
    return ctx
  }
}

export class CelestopolAspectSheet extends CelestopolItemSheet {
  static DEFAULT_OPTIONS = {
    classes: ["aspect"],
    position: { width: 480, height: 360 },
  }
  static PARTS = {
    main: { template: "systems/fvtt-celestopol/templates/aspect.hbs" },
  }
  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.description, { async: true })
    return ctx
  }
}

export class CelestopolEquipmentSheet extends CelestopolItemSheet {
  static DEFAULT_OPTIONS = {
    classes: ["equipment"],
    position: { width: 540, height: 420 },
  }
  static PARTS = {
    main: { template: "systems/fvtt-celestopol/templates/equipment.hbs" },
  }
  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.description, { async: true })
    return ctx
  }
}

export class CelestopolWeaponSheet extends CelestopolItemSheet {
  static DEFAULT_OPTIONS = {
    classes: ["weapon"],
    position: { width: 480, height: 460 },
  }
  static PARTS = {
    main: { template: "systems/fvtt-celestopol/templates/weapon.hbs" },
  }
  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.damageTypes = SYSTEM.WEAPON_DAMAGE_TYPES
    ctx.rangeTypes  = SYSTEM.WEAPON_RANGE_TYPES
    ctx.combatTypes = SYSTEM.WEAPON_COMBAT_TYPES
    ctx.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.description, { async: true })
    return ctx
  }
}

export class CelestopolArmureSheet extends CelestopolItemSheet {
  static DEFAULT_OPTIONS = {
    classes: ["armure"],
    position: { width: 440, height: 380 },
  }
  static PARTS = {
    main: { template: "systems/fvtt-celestopol/templates/armure.hbs" },
  }
  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.description, { async: true })
    return ctx
  }
}
