import { RdDCarac } from "../rdd-carac.js"
import { RollPartCheckbox } from "./roll-part-checkbox.mjs"

export const PART_APPELMORAL = "appelmoral"

export class RollPartAppelMoral extends RollPartCheckbox {

  get code() { return PART_APPELMORAL }
  get useCheckboxTemplate() { return false }
  get isDefaultChecked() { return false }

  visible(rollData) {
    return rollData.active.actor.isPersonnage() && RdDCarac.isActionPhysique(rollData.current.carac.key)
  }

  restore(rollData) {
    this.getCurrent(rollData).checked = this.getSaved(rollData).checked ?? false
  }

  store(rollData, targetData) {
    this.setSaved(targetData, { checked: this.getCurrent(rollData).checked })
  }

  loadRefs(rollData) {
    const refs = this.getRefs(rollData)
    refs.moral = rollData.active.actor.getMoralTotal()
    refs.label = refs.moral > 0 ? "Appel au moral" : "Énergie du désespoir"
  }

  getCheckboxIcon(rollData) {
    const refs = this.getRefs(rollData)
    if (refs.moral > 0) {
      return '<i class="fa-regular fa-face-smile-beam"></i>'
    }
    if (refs.moral < 0) {
      return '<i class="fa-regular fa-face-sad-tear"></i>'
    }
    return '<i class="fa-regular fa-face-meh"></i>'
  }

  getCheckboxLabel(rollData) { return "Appel au moral" }
  getCheckboxValue(rollData) { return 1 }
}
