import { TEMPLATE_DESCRIPTION, TEMPLATE_INVENTAIRE, TEMPLATE_COMESTIBLE } from "../../common/_module.mjs";
import { ITEM_TYPES } from "../../constants.js";
import RdDItemBaseSheet from "./common-item-sheet.mjs";

export default class RdDIngredientSheet extends RdDItemBaseSheet {
  static get ITEM_TYPE() { return ITEM_TYPES.ingredient; }
  static get TEMPLATES() { return [TEMPLATE_DESCRIPTION, TEMPLATE_INVENTAIRE, TEMPLATE_COMESTIBLE]; }

  static DEFAULT_OPTIONS = Object.assign({},
    RdDItemBaseSheet.DEFAULT_OPTIONS,
    {
      classes: ["fvtt-rdd", "item", "ingredient"],
      position: { width: 448 },
      window: { contentClasses: ["ingredient-content"] },
    });

  static PARTS = {
    main: {
      template: "systems/foundryvtt-reve-de-dragon/templates/sheets/item/ingredient.hbs",
    },
  };

  async _prepareContext() {
    const ctx = await super._prepareContext()
    ctx.isBrut = this.document.getUtilisationCuisine() === 'brut'
    return ctx
  }

  async _onRender(context, options) {
    await super._onRender(context, options)

    this.element.querySelector('.preparer-nourriture')?.addEventListener('click', async () => {
      const actor = this.document.parent
      if (actor) await actor.preparerNourriture(this.document)
    })

    this.element.querySelector('.manger-nourriture')?.addEventListener('click', async () => {
      const actor = this.document.parent
      if (actor) await actor.mangerNourriture(this.document)
    })
  }
}
