import { ChangeDetectorRef, Component, Input, NgZone, OnInit } from '@angular/core';
import { AvalonService } from '../../../services/avalon.service';
import { AvalonBase } from '../avalonBase';

@Component({
  selector: 'avalon-vote-result',
  templateUrl: './vote-result.component.html',
  styleUrls: ['./vote-result.component.scss']
})
export class VoteResultComponent extends AvalonBase implements OnInit {

  @Input() isTeamVote: boolean = true;
  constructor(
    protected cdRef: ChangeDetectorRef,
    protected avalonService: AvalonService,
    private ngZone: NgZone
  ) {
    super(cdRef, avalonService);
  }



  public get successText(): string {
    return this.isTeamVote ? '贊成(Approve)' : '成功(Success)';
  }

  public get failedText(): string {
    return this.isTeamVote ? '反對(Reject)' : '失敗(Failed)';
  }

  success: number = 0;
  failed: number = 0;
  ngOnInit(): void {
    if (this.isTeamVote) {
      this.success = this.players.filter(p => p.teamVote == true).length;
      this.failed = this.players.length - this.success;
    } else {

      this.success = this.players.filter(p => p.goingToQuest && p.questVote == true).length;
      this.failed = this.players.filter(p => p.goingToQuest && p.questVote == false).length;
    }
  }
}
