import CelestopolActorSheet from "./base-actor-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"

export default class CelestopolNPCSheet extends CelestopolActorSheet {
  /** @override */
  static DEFAULT_OPTIONS = {
    classes: ["npc"],
    position: { width: 760, height: 600 },
    window: { contentClasses: ["npc-content"] },
  }

  /** @override */
  static PARTS = {
    main:       { template: "systems/fvtt-celestopol/templates/npc-main.hbs" },
    tabs:       { template: "templates/generic/tab-navigation.hbs" },
    competences:{ template: "systems/fvtt-celestopol/templates/npc-competences.hbs" },
    blessures:  { template: "systems/fvtt-celestopol/templates/npc-blessures.hbs" },
  }

  tabGroups = { sheet: "competences" }

  #getTabs() {
    const tabs = {
      competences:{ id: "competences", group: "sheet", icon: "fa-solid fa-dice-d6", label: "CELESTOPOL.Tab.competences" },
      blessures:  { id: "blessures",   group: "sheet", icon: "fa-solid fa-heart-crack", label: "CELESTOPOL.Tab.blessures" },
    }
    for (const v of Object.values(tabs)) {
      v.active   = this.tabGroups[v.group] === v.id
      v.cssClass = v.active ? "active" : ""
    }
    return tabs
  }

  /** @override */
  async _prepareContext() {
    const context  = await super._prepareContext()
    context.tabs   = this.#getTabs()
    context.stats  = SYSTEM.STATS
    context.skills = SYSTEM.SKILLS
    context.anomalyTypes = SYSTEM.ANOMALY_TYPES
    context.woundLevels = SYSTEM.WOUND_LEVELS
    return context
  }

  /** @override */
  async _preparePartContext(partId, context) {
    context.systemFields = this.document.system.schema.fields
    switch (partId) {
      case "competences":
        context.tab = context.tabs.competences
        break
      case "blessures":
        context.tab = context.tabs.blessures
        break
    }
    return context
  }
}
