import { Grammar } from "../grammar.js"
import { CARACS } from "../rdd-carac.js"
import { ReglesOptionnelles } from "../settings/regles-optionnelles.js"
import { ROLL_TYPE_SORT } from "./roll-constants.mjs"
import { RollPartCheckbox } from "./roll-part-checkbox.mjs"

export const PART_ASTROLOGIQUE = "astrologique"

export class RollPartAstrologique extends RollPartCheckbox {

  get code() { return PART_ASTROLOGIQUE }
  get useCheckboxTemplate() { return false }

  visible(rollData) {
    return this.$isUsingAstrologie()
      && (this.isJetChance(rollData) || this.isLancementRituel(rollData))
  }

  isLancementRituel(rollData) {
    return rollData.type.current == ROLL_TYPE_SORT && rollData.current.sort?.sort?.system.isrituel
  }

  isJetChance(rollData) {
    return Grammar.includesLowerCaseNoAccent(rollData.current.carac.key, CARACS.CHANCE)
  }

  $isUsingAstrologie() {
    return ReglesOptionnelles.isUsing("astrologie")
  }

  getCheckboxLabel(rollData) { return "Astrologique" }
  getCheckboxValue(rollData) { return rollData.active.actor.ajustementAstrologique() }
}
