import { _decorator, Component, Node, Sprite } from "cc";
import BaseUI from "../base/BaseUI";
import { AB } from "../base/AB";
const { ccclass, property } = _decorator;

@ccclass("RankingPlayerItem")
export class RankingPlayerItem extends BaseUI {
  init(data: { rank: number; name: string; score: number }) {
    this.setText("lbl_rank", data.rank.toString());
    this.setText("lbl_player_name", "" + data.name);
    this.setText("lbl_score", "" + data.score);

    let bgPath = "textures/ranking/bg_";
    if (data.rank >= 4) {
      bgPath += 4;
    } else {
      bgPath += data.rank;
    }
    AB.inst.setBundleBallImage(bgPath, this.node.getComponent(Sprite));

    let rank_icon_path = "textures/ranking/i_";
    let rank_icon = this.FindAs("icon_rank", Sprite);
    if (data.rank > 3) {
      rank_icon.node.active = false;
    } else {
      rank_icon.node.active = true;
      rank_icon_path += data.rank;
      AB.inst.setBundleBallImage(rank_icon_path, rank_icon);
    }

    let bg_avatar = this.FindAs("bg_avatar", Sprite);
    let bg_avatar_path = "textures/ranking/a_";
    if (data.rank > 3) {
      bg_avatar.node.active = false;
    } else {
      bg_avatar.node.active = true;
      bg_avatar_path += data.rank;
      AB.inst.setBundleBallImage(bg_avatar_path, bg_avatar);
    }
  }
}
