
import { DispatcherManager } from "../GameLogic/DispatcherManager";
import { ui } from "../ui/layaMaxUI";
import DisplayerCarController from "../game_module/DisplayerCarController";
import BannerAndVideo1 from "../game_module/BannerAndVideo1";
import ViewManager, { ViewType } from "../game_module/ViewManager";
import MainView from "./MainView";
import MateManager from "../Manager/MateManager";
import { WXSdk } from "../game_module/WXSdk";

export default class TrialView extends ui.TrialViewUI implements UI_Interface {

    constructor() {
        super();
        this.resizeHander();
        DispatcherManager.on(Laya.Event.RESIZE, this, this.resizeHander);
    }
    OnShow(data?: any) {
        this.InitHandler();
        this.InitDate();
        this.InitHandler();
        this.InitUi();
        BannerAndVideo1.CheatBanner(this.btnBox);
    }
    InitUi() {
        DisplayerCarController.Instance.InitDis(this.viewPort);
    }
    InitDate() {
    }
    InitHandler() {
        this.videoBtn.CZ = () => {
            this.VideoHandler();
        };
        this.backBtn.CZ = () => {
            DisplayerCarController.Instance.Reset();
            this.BackUi();
        }
    }
    VideoHandler() {

        BannerAndVideo1.ShowVideo((isok) => {
            if (isok) {
                WXSdk.AldEvent("看视屏试用");
                this.VideoCom();
            }
        });
    }

    VideoCom() {

        DisplayerCarController.Instance.Reset();
        this.BackUi();
        MateManager.Instance.CreateTryOut();
    }
    BackUi() {
        ViewManager.Instance.CloseView(ViewType.TrialView);
        if(MainView.Instance)MainView.Instance.TryClick();

    }
    OnClose() {
        DispatcherManager.off(Laya.Event.RESIZE, this, this.resizeHander);
        BannerAndVideo1.Clear();
    }

    resizeHander() {
        this.height = Laya.stage.height;
    }
}