import { RdDBaseActorSheetV2 } from "./base-actor-sheet.mjs"
import { ACTOR_TYPES } from "../../constants.js"

export class RdDCreatureSheetV2 extends RdDBaseActorSheetV2 {

  static TYPE = ACTOR_TYPES.creature

  static DEFAULT_OPTIONS = Object.assign({}, RdDBaseActorSheetV2.DEFAULT_OPTIONS, {
    position: { width: 640, height: 720 },
  })

  static PARTS = {
    form: { template: "systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.hbs" },
  }

  async _onRender(context, options) {
    await super._onRender(context, options)
    if (!this.isEditable) return

    this.html.find(".creature-carac").change(async event => {
      const compName = event.currentTarget.attributes.compname.value
      await this.actor.updateCreatureCompetence(compName, "carac_value", parseInt(event.target.value))
    })
    this.html.find(".creature-niveau").change(async event => {
      const compName = event.currentTarget.attributes.compname.value
      await this.actor.updateCreatureCompetence(compName, "niveau", parseInt(event.target.value))
    })
    this.html.find(".creature-dommages").change(async event => {
      const compName = event.currentTarget.attributes.compname.value
      await this.actor.updateCreatureCompetence(compName, "dommages", parseInt(event.target.value))
    })
  }
}
