import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { rankData } from '../../data';
import { tools } from '../../tools';
import { GameManager } from '../../GameManager';
const { ccclass, property } = _decorator;

@ccclass('rank_my_info')
export class rank_my_info extends Component {
    @property(Node) img_weishangbang:Node = null
    @property(Node) icon_number_bg:Node = null
    @property(Node) icon_number_img:Node = null
    @property(Node) icon_number_other_bg:Node = null
    @property(Node) lab_number_other:Node = null
    @property(SpriteFrame) sf_rank_icon_1:SpriteFrame = null
    @property(SpriteFrame) sf_rank_icon_2:SpriteFrame = null
    @property(SpriteFrame) sf_rank_icon_3:SpriteFrame = null

    @property(Node) img_avatar:Node = null
    @property(Node) lab_nickname:Node = null
    @property(Node) lab_score:Node = null
    @property(Node) img_car:Node = null

    initView(data:rankData) {
        if(data.number==0) {
            this.img_weishangbang.active = true
            this.icon_number_bg.active = false
            this.icon_number_other_bg.active = false
        } else {
            this.img_weishangbang.active = false
            if(data.number<=3) {
                this.icon_number_bg.active = true
                switch (data.number) {
                    case 1:
                        this.icon_number_img.getComponent(Sprite).spriteFrame = this.sf_rank_icon_1
                        break;
                    case 2:
                        this.icon_number_img.getComponent(Sprite).spriteFrame = this.sf_rank_icon_2
                        break;
                    case 3:
                        this.icon_number_img.getComponent(Sprite).spriteFrame = this.sf_rank_icon_3
                        break;
                    default:
                        break;
                }
            } else {
                this.icon_number_other_bg.active = true
                this.lab_number_other.getComponent(Label).string = data.number + ''
            }
        }
        
        tools.loadRemoteImg(data.avatarUrl, (r)=>{
            this.img_avatar.getComponent(Sprite).spriteFrame = r.sf
        })
        this.lab_nickname.getComponent(Label).string = data.nickName
        this.lab_score.getComponent(Label).string = data.score + ' 分'
        this.img_car.getComponent(Sprite).spriteFrame = GameManager.getUserDefaultRankCarSf()
    }
}

