import {PanelBaseControl} from "../Control/PanelBaseControl";
import { ViewManager } from "../View/ViewManager";
import {pingtaiutils} from "../WXSDK/pingtaiutils";
import {ViewAction} from "../utils/ViewAction";
import {SkinData} from "../Data/SkinData";
import { GameUtils } from "../utils/GameUtils";
import { AssetPath } from "../Config/AssetPath";
import {AgencyTrial} from "../Agency/AgencyTrial";
import {GuangGao} from "../WXSDK/GuangGao";
import { ttad } from "../WXSDK/ttad";
import { TimerService } from "../Time/TimerService";

export class TrialPanel extends PanelBaseControl 
{
    static key:string = "TrialPanel";


    load_icon:fairygui.GLoader;
    btn_video:fairygui.GButton;
    btn_close:fairygui.GLoader;

    skinarr:Array<SkinData>;
    private _selectvo:SkinData;
    private agencytrial:AgencyTrial;

    constructor( arr:Array<SkinData> ) 
    { 
        super("main","shiyongView",false,ViewAction.ActionType_none,1); 
        this.skinarr = arr;
    }

    protected onInit():void
    {
        super.onInit();
    }

    protected initView():void
    {
        this.agencytrial = this.getProxy( AgencyTrial );
        var index:number = GameUtils.randRangeint( 0,this.skinarr.length-1 );
        this._selectvo = this.skinarr[ index ];
        this.load_icon.url = AssetPath.getroleicon( this._selectvo.roleCFG.icon );
        // pingtaiutils.Instance.createBanner( "ShiYongView" );
        GuangGao.CheatBanner(this.btn_close);
    }

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

    private videofun():void
    {
        // pingtaiutils.Instance.playVideo( "",this,this.videocallback );
        this.videocallback();
    }

    private videocallback():void
    {
        ttad.ShowVideo((isLoad=>{
            if(isLoad){
                this.agencytrial.ExitPanel( this._selectvo );
            }
        }))
    }

    private onclosefun():void
    {
        this.agencytrial.ExitPanel( null );
    }

    public destory():void
    {
        // GuangGao.Clear();
        ttad.Clear();
        super.destory();
    }
}