
export class RankStatisticsManager {

  MESSAGE_RANK = 'hw-gameRank';
  _rankDataList = [];

  // set rankDataList(arr) {
  //   this._rankDataList = arr;
  // }
  //
  get rankDataList() {
    return this._rankDataList;
  }

  addRankDataToList(data) {

    for (let i = 0; i < this._rankDataList.length; ++i) {
      if (this._rankDataList[i].uuid == data.uuid) {
        this._rankDataList.splice(i, 1);
        break;
      }
    }
    this._rankDataList.push(data);

    this._rankDataList.sort((a, b) => {
      if (a.rightNum === b.rightNum) {
        return a.duration - b.duration;
      } else {
        return b.rightNum - a.rightNum;
      }
    });

  }

  getOneRankData(uuid) {
    console.log('getOneRankData uuid: ', uuid );
    console.log('this._rankDataList: ', this._rankDataList );
    for (let i = 0; i < this._rankDataList.length; i++) {
      console.log('---- uuid: ', this._rankDataList[i].uuid);
      if (this._rankDataList[i].uuid == uuid) {
        return this._rankDataList[i];
      }
    }
  }


  sendRankDataEvent(otherData = null) {
    const data = {rankData: this._rankDataList};
    if (otherData) {
      for (const key in otherData) {
        data[key] = otherData[key];
      }
    }
    (<any> window).courseware.sendEvent(this.MESSAGE_RANK, data);
  }
}
