// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";

const { ccclass, property } = cc._decorator;

@ccclass
export default class PaiHangBangItem extends cc.Component {
    @property(cc.Label)
    mingciLab: cc.Label = null;
    @property(cc.Label)
    nameLab: cc.Label = null;
    @property(cc.Label)
    levelLab: cc.Label = null;
    @property(cc.Label)
    chenghaoLab: cc.Label = null;

    @property(cc.Sprite)
    diban: cc.Sprite = null;

    @property(cc.Sprite)
    mingciTag: cc.Sprite = null;

    @property(cc.Sprite)
    headIcon: cc.Sprite = null;


    @property([cc.SpriteFrame])
    dikuangs: cc.SpriteFrame[] = [];


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    configDate = null

    setViewDate(config, idx) {
        this.configDate = config

        let mingci = config.rank
        this.mingciLab.string = mingci + ''
        this.levelLab.string = this.configDate.score
        this.chenghaoLab.string = JSON.parse(this.configDate.remark).chenghao
        this.nameLab.string = this.configDate.nickname ? this.truncateString(this.configDate.nickname, 3) + '' : this.configDate.nickname

        // Common5.addUrlSprite_custom("paihangbang/"+this.configDate.id,this.headIcon)
        // Common5.addUrlSprite_custom(this.configDate.pic, this.headIcon)

        if (config.rank == 1) {
            this.mingciTag.node.active = true
            // Common5.addUrlSprite_custom("paihangbang/第一名",this.mingciTag)
            // Common5.addUrlSprite_custom("paihangbang/第一名bg1",this.diban)
            this.diban.spriteFrame = this.dikuangs[0]
        } else if (config.rank == 2) {
            this.mingciTag.node.active = true
            // Common5.addUrlSprite_custom("paihangbang/第二名",this.mingciTag)
            // Common5.addUrlSprite_custom("paihangbang/第二名bg2",this.diban)
            this.diban.spriteFrame = this.dikuangs[1]
        } else if (config.rank == 3) {
            this.mingciTag.node.active = true
            // Common5.addUrlSprite_custom("paihangbang/第三名",this.mingciTag)
            // Common5.addUrlSprite_custom("paihangbang/第三名bg",this.diban)
            this.diban.spriteFrame = this.dikuangs[2]
        } else {
            // Common5.addUrlSprite_custom("paihangbang/普通2",this.diban)
            this.mingciTag.node.active = false
            this.diban.spriteFrame = this.dikuangs[3]
        }



    }

    start() {

    }

    truncateString(str: string, maxLength: number): string {
        return str.length > maxLength ? str.slice(0, maxLength) + '' : str;
    }

    // update (dt) {}
}