import CpaItem from "./CpaItem";
import { RecommendItem, Recommend } from "./RecommendView";
import { ViewManager } from "../View/ViewManager";
import { PanelBaseControl } from "../Control/PanelBaseControl";
import { GameUtils } from "../utils/GameUtils";
import { FYHD_Sdk } from "../WXSDK/FYHD_Sdk";

export default class TuijianView extends PanelBaseControl 
{
    static key:string = "TuijianView";
    btn_close:fairygui.GLoader;
    list_1:fairygui.GList;
    list_2:fairygui.GList;
    private _nowlist1:RecommendItem[];
    private _nowlist2:RecommendItem[];
    private more:fairygui.GLoader;

    constructor() 
    { 
        super( "main","tuijianView" ); 
    }
    
    protected initView():void
    {
        this.list_1.setVirtual();
        this.list_1.itemRenderer = Laya.Handler.create( this,this.itemrenderlist1,null,false );
        this.list_2.setVirtual();
        this.list_2.itemRenderer = Laya.Handler.create(this,this.itemrenderlist2,null,false);

        this._nowlist1 = Recommend.gdyxData;
        this._nowlist2 = Recommend.gdyxData;
        this.list_1.numItems = 7;
        this.list_2.numItems = this._nowlist2.length;
    }

    protected initEvent():void
    {
        this.AddEventByType( this.btn_close,Laya.Event.CLICK,this,this.onclosefun );
        this.AddEventByType( this.more,Laya.Event.CLICK,this,this.JumpApp );
    }

    private itemrenderlist1( index:number,item:CpaItem ):void
    {
        if( index < 7 )
        {
            item.showData( this._nowlist1[index] );
        }
    }
    
    private itemrenderlist2( index:number,item:CpaItem ):void
    {
        if( index < this._nowlist2.length )
        {
            item.showData( this._nowlist2[index] );
        }
    }

    private onclosefun():void
    {
        ViewManager.Instance.close( TuijianView );
    }

    //随机跳转游戏
    private JumpApp():void{
        let ran = GameUtils.randRangeint(0,this._nowlist1.length-1);
        FYHD_Sdk.ShowHuTuiJump(this._nowlist1[ran],false);
    }
}