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

/**
 * The Combatant configuration application.
 * @extends DocumentSheetV2
 * @mixes HandlebarsApplication
 */
export default class CombatantConfig extends HandlebarsApplicationMixin(DocumentSheetV2) {
  /** @inheritDoc */
  static DEFAULT_OPTIONS = {
    classes: ["combatant-config"],
    canCreate: true,
    window: {
      contentClasses: ["standard-form"],
      icon: "fa-solid fa-sword"
    },
    position: {width: 420},
    form: {
      closeOnSubmit: true
    }
  };

  /** @override */
  static PARTS = {
    body: {
      root: true,
      template: "templates/sheets/combatant-config.hbs"
    },
    footer: {template: "templates/generic/form-footer.hbs"}
  };

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

  /** @override */
  get title() {
    const combatant = this.document;
    const key = combatant.collection?.has(combatant.id) ? "COMBATANT.UpdateNamed" : "COMBATANT.ACTIONS.Create";
    return _loc(key, {name: combatant.name});
  }

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

  /** @inheritDoc */
  async _prepareContext(options) {
    const context = await super._prepareContext(options);
    const combatant = context.document;
    const submitLabel = combatant.collection?.has(combatant.id)
      ? "COMBATANT.ACTIONS.Update"
      : "COMBATANT.ACTIONS.Create";
    context.buttons = [{type: "submit", icon: "fa-solid fa-floppy-disk", label: submitLabel}];
    return context;
  }
}
