import {Text} from "pixi.js";
import HackAttachment from "../HackAttachment.js";
import {capitalizeFirstLetter, tryToApplyFallbackFontFamily} from "../../utils/utils";
import Locator from "../../services/Locator";
import AdvancedText from "../../utils/AdvancedText";

export default class FreespinsIndicator extends HackAttachment {

  set label(v) {
    this._label = v;
    this.labelText.text = v;
  }

  set issued(v) {
    this._issued = v;
    this._updateIndication();
  }

  set left(v) {
    this._left = v;
    this._updateIndication();
  }

  _updateIndication() {
    this.valueText.text = `${this._left}/${this._issued}`
  }

  createContent() {
    const maxWidth = 58;
    const label = new AdvancedText({key: 'freespins'}, {
      fontFamily: "Oxanium, Opensans",
      fill: 0xffffff,
      fontWeight: 400,
      fontSize: 12,
      lineHeight: 11,
      align: "right",
      wordWrap: true,
      wordWrapWidth: maxWidth,
    });
    tryToApplyFallbackFontFamily(label);
    label.anchor.set(1, 1);
    label.position.set(this.size.width, this.size.height * 0.5);
    label.scale.set(Math.min(maxWidth / label.width, 1));
    label.resolution = this.texture.resolution;
    this.labelText = label;

    const value = new Text("0/0", {
      fontFamily: "Oxanium, Opensans",
      fill: 0xffffff,
      fontWeight: "bold",
      fontSize: 14,
      align: "right",
    });
    tryToApplyFallbackFontFamily(value);
    value.anchor.set(1, 0);
    value.position.set(this.size.width, this.size.height * 0.5);
    value.resolution = this.texture.resolution;
    this.container.addChild(label, value);

    this.valueText = value;
  }
}
