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

export default class VermineNpcSheetV2 extends VermineBaseActorSheet {

  static DEFAULT_OPTIONS = {
    classes: ["npc"],
    position: { width: 750, height: 680 },
    window: { contentClasses: ["npc-content"] }
  }

  static PARTS = {
    main: { template: "systems/vermine2047/templates/actor/appv2/npc-main.hbs" },
    tabs: { template: "templates/generic/tab-navigation.hbs" },
    characteristics: { template: "systems/vermine2047/templates/actor/appv2/npc-characteristics.hbs" },
    skills: { template: "systems/vermine2047/templates/actor/appv2/npc-skills.hbs" },
    threat: { template: "systems/vermine2047/templates/actor/appv2/npc-threat.hbs" },
    combat: { template: "systems/vermine2047/templates/actor/appv2/npc-combat.hbs" },
    notes: { template: "systems/vermine2047/templates/actor/appv2/npc-notes.hbs" }
  }

  tabGroups = { sheet: "characteristics" }

  #getTabs() {
    const tabs = {
      characteristics: { id: "characteristics", group: "sheet", icon: "fas fa-dice", label: "VERMINE.abilities" },
      skills: { id: "skills", group: "sheet", icon: "fas fa-brain", label: "VERMINE.skills" },
      threat: { id: "threat", group: "sheet", icon: "fas fa-exclamation-triangle", label: "ADVERSITY.threat" },
      combat: { id: "combat", group: "sheet", icon: "fas fa-sword", label: "VERMINE.combat" },
      notes: { id: "notes", group: "sheet", icon: "fas fa-sticky-note", label: "IDENTITY.notes" }
    }
    for (const v of Object.values(tabs)) {
      v.active = this.tabGroups[v.group] === v.id
      v.cssClass = v.active ? "active" : ""
    }
    return tabs
  }

  async _prepareContext() {
    const context = await super._prepareContext()
    context.tabs = this.#getTabs()
    return context
  }

  async _preparePartContext(partId, context) {
    const doc = this.document
    switch (partId) {
      case "main":
        context.npcThreatOptions = CONFIG.VERMINE.npcThreatLevels
        context.npcExperienceOptions = CONFIG.VERMINE.npcExperienceLevels
        context.npcRoleOptions = CONFIG.VERMINE.npcRoleLevels
        context.totemOptions = CONFIG.VERMINE.totems
        context.originOptions = CONFIG.VERMINE.origins
        break
      case "characteristics":
        context.tab = context.tabs.characteristics
        break
      case "skills":
        context.tab = context.tabs.skills
        break
      case "threat":
        context.tab = context.tabs.threat
        break
      case "combat":
        context.tab = context.tabs.combat
        const { prepareActiveEffectCategories } = await import("../../system/effects.mjs")
        context.effects = prepareActiveEffectCategories(doc.effects)
        break
      case "notes":
        context.tab = context.tabs.notes
        break
    }
    return context
  }
}
