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

export default class AwECreatureSheet extends AwEActorSheet {
  /** @override */
  static DEFAULT_OPTIONS = {
    classes: ["creature"],
    position: {
      width: 700,
      height: 700
    },
    window: {
      contentClasses: ["creature-content"]
    }
  }

  /** @override */
  static PARTS = {
    header: {
      template: "systems/fvtt-adventures-with-emmy/templates/creature-header.hbs"
    },
    tabs: {
      template: "templates/generic/tab-navigation.hbs"
    },
    main: {
      template: "systems/fvtt-adventures-with-emmy/templates/creature-main.hbs"
    },
    description: {
      template: "systems/fvtt-adventures-with-emmy/templates/creature-description.hbs"
    },
    eureka: {
      template: "systems/fvtt-adventures-with-emmy/templates/creature-eureka.hbs"
    }
  }

  /** @override */
  tabGroups = {
    sheet: "main"
  }

  #getTabs() {
    const tabs = {
      main: { id: "main", group: "sheet", icon: "fa-solid fa-dragon", label: "AWEMMY.Sheet.Tab.Main" },
      description: { id: "description", group: "sheet", icon: "fa-solid fa-scroll", label: "AWEMMY.Sheet.Tab.Description" },
      eureka: { id: "eureka", group: "sheet", icon: "fa-solid fa-lightbulb", label: "AWEMMY.Sheet.Tab.Eureka" }
    }
    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.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
      this.document.system.description, { async: true }
    )
    return context
  }

  /** @override */
  async _preparePartContext(partId, context) {
    switch (partId) {
      case "main":
        context.tab = context.tabs.main
        break
      case "description":
        context.tab = context.tabs.description
        break
      case "eureka":
        context.tab = context.tabs.eureka
        break
    }
    return context
  }
}
