import {DocumentSheetV2, HandlebarsApplicationMixin} from "../api/_module.mjs";

/**
 * @import {ApplicationConfiguration, FormFooterButton} from "../_types.mjs";
 * @import {DocumentSheetConfiguration} from "../api/document-sheet.mjs";
 */

/**
 * @deprecated since v14
 * @ignore
 */
export default class MeasuredTemplateConfig extends HandlebarsApplicationMixin(DocumentSheetV2) {
  constructor(...args) {
    const msg = "MeasuredTemplateConfig is deprecated because the MeasuredTemplate document has been merged into the functionality of the Region document.";
    foundry.utils.logCompatibilityWarning(msg, {since: 14, until: 16, once: true});
    super(...args);
  }

  /* -------------------------------------------- */

  /** @inheritDoc */
  static DEFAULT_OPTIONS = {
    classes: ["template-config"],
    canCreate: true,
    window: {
      contentClasses: ["standard-form"],
      icon: "fa-solid fa-ruler-combined",
      resizable: true
    },
    position: {width: 480},
    form: {closeOnSubmit: true}
  };

  /** @override */
  static PARTS = {
    main: {template: "templates/scene/template-config.hbs", scrollable: [""]},
    footer: {template: "templates/generic/form-footer.hbs"}
  };

  /* -------------------------------------------- */

  /** @inheritDoc */
  async _prepareContext(options) {
    const context = await super._prepareContext(options);
    const document = context.document;
    const templateTypes = {circle: "Circle", cone: "Cone", rect: "Rectangle", ray: "Ray"};
    const units = {
      degrees: _loc("MEASUREMENT.Degrees"),
      gridUnits: document.parent.grid.units || _loc("MEASUREMENT.GridUnits"),
      pixels: _loc("MEASUREMENT.Pixels")
    };
    const submitText = document.collection?.has(document.id) ? "REGION.ACTIONS.update" : "REGION.ACTIONS.create";
    return Object.assign(context, {
      templateTypes,
      units,
      userColor: game.user.color,
      buttons: [{type: "submit", icon: "fa-solid fa-floppy-disk", label: submitText}]
    });
  }
}
