import { RdDTextEditor } from "../apps/rdd-text-roll-editor.js";
import { SYSTEM_RDD } from "../constants.js";
import { Misc } from "../misc.js";


export class RdDJournalSheet extends foundry.appv1.sheets.JournalTextPageSheet {
  static register() {
    foundry.applications.apps.DocumentSheetConfig.unregisterSheet(JournalEntryPage, "core", foundry.appv1.sheets.JournalTextPageSheet)
    foundry.applications.apps.DocumentSheetConfig.registerSheet(JournalEntryPage,
      SYSTEM_RDD,
      RdDJournalSheet, {
      types: ["text"],
      makeDefault: true,
    });
  }

  async getData(options) {
    const journalData = await super.getData(options);
    journalData.editor.content = await RdDTextEditor.enrichHTML(journalData.document.text.content, this.object)
    return journalData
  }

  activateListeners(html) {
    super.activateListeners(html);

    html.find('.roll-text').click(async event => await RdDTextEditor.rollText(event, this.actor))
    html.find('.chat-roll-text').click(async event => await RdDTextEditor.chatRollText(event))
  }
}