import { _decorator, Component, Node, Sprite } from 'cc';
import { uiManager } from '../../manager/uiManager';
import { config } from '../../config';
import { tools } from '../../tools';
import { imageCacheManager } from '../../manager/imageCacheManager';
const { ccclass, property } = _decorator;

@ccclass('home_bottom')
export class home_bottom extends Component {
    @property(Node) btn_up_rank:Node = null
    @property(Node) btn_wenhao:Node = null
    @property(Node) btn_gengduo:Node = null
    @property(Node) img_rank_car_1:Node = null
    @property(Node) img_rank_car_2:Node = null
    @property(Node) img_rank_car_3:Node = null
    start() {
        uiManager.Instance().onButtonListen(this.btn_up_rank, ()=>{
            uiManager.Instance().showUi(config.UI.rank)
        })
        uiManager.Instance().onButtonListen(this.btn_wenhao, ()=>{
            uiManager.Instance().showUi(config.UI.ui_unLock_view)
        })
        uiManager.Instance().onButtonListen(this.btn_gengduo, ()=>{
            uiManager.Instance().showUi(config.UI.rank)
        })
    }

    public init() {

    }
    
    public reloadCountryRankData(){
        tools.requestRankList(0, (d_content)=>{
            let data = null
            if(d_content.length>0) {
                data = d_content[0]
                this.img_rank_car_1.getComponent(Sprite).spriteFrame = imageCacheManager.getRankCarImageById(data.car_id)
            } else if(d_content.length>1) {
                data = d_content[1]
                this.img_rank_car_2.getComponent(Sprite).spriteFrame = imageCacheManager.getRankCarImageById(data.car_id)
            } else if(d_content.length>2) {
                data = d_content[2]
                this.img_rank_car_3.getComponent(Sprite).spriteFrame = imageCacheManager.getRankCarImageById(data.car_id)
            }
        })
    }
}


