
import { DispatcherManager } from "../Game/DispatcherManager";
import { ui } from "../ui/layaMaxUI";
import {DisplayerCarController} from "../Net/DisplayerCarController";
import {GuangGao} from "../Net/GuangGao";
import  {ViewManager, ViewType } from "../Net/ViewManager";
import MainView from "./MainView";
import {MateManager} from "../Manager/MateManager";
import { WXSdk } from "../Net/WXSdk";

export default class TrialView extends ui.TrialViewUI implements SC {

    constructor() {
        super();
        this.Resize();
        DispatcherManager.on(Laya.Event.RESIZE, this, this.Resize);
    }
    OnShow(data?: any) {
        this.RegButton();
        this.RefreshData();
        this.RegButton();
        this.RefreshUI();
        GuangGao.CheatBanner(this.btnBox);
    }
    RefreshUI() {
        DisplayerCarController.Instance.InitDis(this.viewPort);
    }
    RefreshData() {
    }
    RegButton() {
        this.videoBtn.CZ = () => {
            this.VideoHandler();
        };
        this.backBtn.CZ = () => {
            DisplayerCarController.Instance.Reset();
            this.BackUi();
        }
    }
    VideoHandler() {

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

    VideoCom() {
        DisplayerCarController.Instance.Reset();
        this.BackUi();
        MateManager.Instance.Trial();
    }
    BackUi() {
        ViewManager.Instance.CloseView(ViewType.TrialView);
        if(MainView.Instance)MainView.Instance.TryClick();
    }
    OnClose() {
        DispatcherManager.off(Laya.Event.RESIZE, this, this.Resize);
        GuangGao.Clear();
    }

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