import { gameProperties, playerProperties, graphicAssets, soundAssets, audioAssets, fontAssets, labels } from '../config';

export default class UI extends Phaser.Group {
  constructor(state) {
    super(state.game);

    this.state = state;

    this.tf_scoreLeft = this.game.add.text(fontAssets.scoreLeft_x, fontAssets.scoreTop_y, "0", fontAssets.scoreFontStyle);
    this.tf_scoreLeft.anchor.set(0.5, 0);
    this.tf_scoreLeft.visible = false;

    this.tf_scoreRight = this.game.add.text(fontAssets.scoreRight_x, fontAssets.scoreTop_y, "0", fontAssets.scoreFontStyle);
    this.tf_scoreRight.anchor.set(0.5, 0);
    this.tf_scoreRight.visible = false;

    this.instructions = this.game.add.text(this.game.world.centerX, 370, labels.instructions, fontAssets.instructionsFontStyle);
    this.instructions.anchor.set(0.5, 0.5);

    this.winnerLeft = this.game.add.text(gameProperties.screenWidth * 0.25, gameProperties.screenHeight * 0.25, labels.winner, fontAssets.instructionsFontStyle);
    this.winnerLeft.anchor.set(0.5, 0.5);

    this.winnerRight = this.game.add.text(gameProperties.screenWidth * 0.75, gameProperties.screenHeight * 0.25, labels.winner, fontAssets.instructionsFontStyle);
    this.winnerRight.anchor.set(0.5, 0.5);


    this.hideTextFields();
  }

  updateScoreTextFields() {
    this.tf_scoreLeft.text = this.state.paddleLeftSprite.score.toString();
    this.tf_scoreRight.text = this.state.paddleRightSprite.score.toString();
  }

  hideTextFields() {
    this.instructions.visible = false;
    this.winnerLeft.visible = false;
    this.winnerRight.visible = false;
  }

  prepareDemo() {
    this.tf_scoreLeft.fill = '#FFF';
    this.tf_scoreRight.fill = '#FFF';
    this.instructions.visible = true;
  }

  prepareGame() {
    this.tf_scoreLeft.fill = '#000';
    this.tf_scoreRight.fill = '#000';
    this.tf_scoreLeft.visible = true;
    this.tf_scoreRight.visible = true;
    this.hideTextFields();
  }

  winner(side) {
    if (side === 'left') {
      this.winnerLeft.visible = true;
    }
    else if (side === 'right'){
      this.winnerRight.visible = true;
    }
  }

}