import { TeDeumUtility } from "../common/tedeum-utility.js";
export class TeDeumRollDialog extends Dialog {
  /* -------------------------------------------- */
  static async create(actor, rollData) {
    let options = { classes: ["tedeum-roll-dialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
    let html = await renderTemplate('systems/fvtt-te-deum/templates/dialogs/roll-dialog-generic.hbs', rollData);
    return new TeDeumRollDialog(actor, rollData, html, options);
  }
  /* -------------------------------------------- */
  constructor(actor, rollData, html, options, close = undefined) {
    let conf = {
      title: "Lancer !",
      content: html,
      buttons: {
        roll: {
          icon: '',
          label: "Lancer",
          callback: () => { this.roll() }
        },
        cancel: {
          icon: '',
          label: "Annuler",
          callback: () => { this.close() }
        }
      },
      close: close
    }
    super(conf, options);
    this.actor = actor;
    this.rollData = rollData;
  }
  /* -------------------------------------------- */
  roll() {
    TeDeumUtility.rollTeDeum(this.rollData)
  }
  /* -------------------------------------------- */
  async refreshDialog() {
    const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
    this.data.content = content
    this.render(true)
  }
  /* -------------------------------------------- */
  activateListeners(html) {
    super.activateListeners(html);
    let dialog = this;
    function onLoad() {
    }
    $(function () { onLoad(); });
    html.find('#bonusMalusPerso').change((event) => {
      this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
    })
    html.find('#roll-difficulty').change((event) => {
      this.rollData.difficulty = String(event.currentTarget.value) || "pardefaut"
    })
    html.find('#roll-bonus-malus').change((event) => {
      this.rollData.bonusMalus = event.currentTarget.value || "0"
    })
    html.find('#roll-enable-providence').change((event) => {
      this.rollData.enableProvidence = event.currentTarget.checked
    })
    
    
  }
}