import WinText from "./WinText.js";
import HackAttachment from "../HackAttachment.js";
import Locator from "../../services/Locator";
import {capitalizeFirstLetter} from "../../utils/utils";

export default class WinIndicator extends HackAttachment {
  createContent(options) {
    this._win = new WinText({resolution: this.texture.resolution});
    this._win.label = capitalizeFirstLetter(Locator.locales.get("win"));
    this._win.value = "";
    this._win.position.set(this.size.width * 0.5, this.size.height * 0.5);
    this._totalWin = new WinText({resolution: this.texture.resolution});
    this._totalWin.label = capitalizeFirstLetter(Locator.locales.get("total_win"));
    this._totalWin.value = "";
    this._totalWin.position.set(this.size.width * 0.5, this.size.height * 0.5);
    this.container.addChild(this._win, this._totalWin);

    this.win = null;
    this.totalWin = null;
  }

  set totalWin(value) {
    this._totalWin.value = value;
    this._totalWin.visible = value !== null;
    this.adjust();
  }

  set win(value) {
    this._win.value = value;
    this._win.visible = value !== null;
    this.adjust();
  }

  adjust() {
    this._totalWin.x = (this.size.width - this._totalWin.width) * 0.5;
    this._totalWin.y = (this.size.height - this._totalWin.height) * 0.5;
    this._win.x = (this.size.width - this._win.width) * 0.5;
    this._win.y = (this.size.height - this._win.height) * 0.5;
    this._totalWin.y -= this._win.visible ? this._totalWin.height * 0.5 : 0;
    this._win.y += this._totalWin.visible ? this._win.height * 0.5 : 0;
  }
}
