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

export class RdDActorVehiculeSheetV2 extends RdDBaseActorSheetV2 {

  static TYPE = ACTOR_TYPES.vehicule

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

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

  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.editable = this.isEditable
    ctx.cssClass = this.isEditable ? "editable" : "locked"
    ctx.effects = this.actor.effects
    ctx.limited = this.actor.limited
    ctx.owner = this.actor.isOwner
    this.recherche = undefined
    return ctx
  }

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

    this.html.find(".resistance-moins").click(async event => await this.actor.vehicleIncDec("resistance", -1))
    this.html.find(".resistance-plus").click(async event => await this.actor.vehicleIncDec("resistance", 1))
    this.html.find(".structure-moins").click(async event => await this.actor.vehicleIncDec("structure", -1))
    this.html.find(".structure-plus").click(async event => await this.actor.vehicleIncDec("structure", 1))
  }
}
