import { _decorator, Component, Node } from 'cc';
import { JNGLayerBase } from '../../../components/JNComponent';
import { API } from '../../../consts/API';
import { TD } from '../../../App';
import JNScrollView from '../../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
import { OnHookRinkingItem } from './OnHookRinkingItem';
import PlayerData from '../../../data/PlayerData';
const { ccclass, property } = _decorator;

/**
 * OnHook 排行榜
 */
@ccclass('OnHookRinkingView')
export class OnHookRinkingView extends JNGLayerBase {

    mapId:number;

    @property(JNScrollView)
    rankings:JNScrollView;

    @property(OnHookRinkingItem)
    myItem:OnHookRinkingItem;

    onJNLoad(mapId?: number): void {

        this.mapId = mapId || TD.TbGOnHookMaps.getDataList()[0].id;
        super.onJNLoad(mapId);

        this.onInit();
        
    }

    async onInit(){

        let ranks = await API.GOnHookRankings(this.mapId);

        this.rankings.refreshData(ranks.filter(item => item.rank <= 10));
        let myData = ranks.filter(item => item.playerId == PlayerData.getIns().data.playerId)[0]
        if(myData)
            this.myItem.onInit(myData);

    }

}


