import {PanelChildControl} from "../Control/PanelChildControl";
import { RecommendItem, Recommend } from "./RecommendView";
import { GameUtils } from "../utils/GameUtils";
import { ViewManager } from "../View/ViewManager";
import ChoutiPanView from "./ChoutiPanView";
import { WxApi } from "../WXSDK/Sdk";
import { FYHD_Sdk } from "../WXSDK/FYHD_Sdk";

export default class CpaItem extends PanelChildControl 
{
    img_tip:fairygui.GImage;
    load_icon:fairygui.GLoader;
    txt_word:fairygui.GTextField;
    txt_word1:fairygui.GTextField;
    private _vo:RecommendItem;
    private ispenchoutipan:boolean = false;
    constructor() { super(); }
    
    public onInit():void
    {
        this.name = "capItem";
        this.AddEventByType( this,Laya.Event.CLICK,this,this.onbtnclick );
    }

    private onbtnclick():void
    {
        if( this._vo )
        {
            var data:RecommendItem = this._vo;
            FYHD_Sdk.ShowHuTuiJump(data,this.ispenchoutipan);
            // var appid = data.to_appid;
            // var path = data.jump_path;
            // let param = {"appId":appid.toString(),"path":path.toString()};
            // if(Laya.Browser.onMobile)
            // {
            //     Laya.Browser.window.wx.navigateToMiniProgram(
            //     {
            //         appId:appid.toString(),
            //         path:path.toString(),
            //         success:res=>
            //         {
            //             WxApi.recordAldEvent("跳转到游戏失成功","1");
            //         },
            //         fail:res=>
            //         {
            //             if( this.ispenchoutipan )
            //             {
            //                 ViewManager.Instance.add( ChoutiPanView );
            //             }
            //         }
            //     });
            // }
        }
    }

    public showData( data:RecommendItem,isopenchoutipan:boolean = false ):void
    {
        this.ispenchoutipan = isopenchoutipan;
        this._vo = data;
        if( data )
        {
            this.load_icon.url = data.icon;
            if( this.txt_word )
            {
                this.txt_word.text = data.togame_name;
            }
            if( this.img_tip )
            {
                this.img_tip.visible = Math.random() > 0.5?true:false;
            }
            if( this.txt_word1 )
            {
                this.txt_word1.text = GameUtils.randRangeint(235470,1561430).toString() + "人玩";
            }
        }
        
    }
}