import { ui } from "../ui/layaMaxUI";
import { ViewManager, ViewType } from "../Net/ViewManager";
import { FYHD_Sdk } from "../Net/FYHD_Sdk";
import { GameTool } from "../Util/GameTool";
import { GuangGao } from "../Net/GuangGao";


export default class ExportView extends ui.ExportViewUI{
    jump = false;
    OnShow(data?){
        this.CloseBtn.clickHandler = Laya.Handler.create(this,this.ClickClose,null,false);
        this.ContinueBtn.clickHandler = Laya.Handler.create(this,this.ClickContinue,null,false);
        this.SetData();
        this.ContinueBtn.visible = FYHD_Sdk.iswhite;
        if(FYHD_Sdk.iswhite){
            Laya.timer.once(1000,this,()=>{
                // GuangGao.OpenBanner();
            })
        }
        this.height = Laya.stage.height;
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
        })
    }
    OnClose(){
        Laya.timer.clearAll(this);
    }
    ClickClose(_data){
        ViewManager.Instance.CloseView(ViewType.ExportView);
    }
    ClickContinue(){
        let ran = GameTool.randomInt(0,FYHD_Sdk.pushData.length);
        let item = FYHD_Sdk.pushData[ran];
        FYHD_Sdk.ClickAd(FYHD_Sdk.Ad_ClickType.PushClick);
        FYHD_Sdk.ShowHuTuiJump(item);
    }
    SetData() {
        FYHD_Sdk.SetHuTuiList(this.TopList,2,"");
        FYHD_Sdk.SetHuTuiList(this.BottomList,1,"");
        this.GunGun();
    }
    // GunGun() {
    //     var maxTop;
    //     var maxBtm;
    //     try {
    //         this.BottomList.scrollBar.value = 0;
    //         this.TopList.scrollBar.value = 0;
    //         maxTop = this.TopList.scrollBar.max;
    //         maxBtm = this.BottomList.scrollBar.max;
    //     } catch (error) {
    //         console.error(error);
    //         return;
    //     }
    //     var tempTop = 1;
    //     var tempBtm = 1;
    //     Laya.timer.frameLoop(1, this, () => {
    //         this.TopList.scrollBar.value += tempTop;
    //         if (this.TopList.scrollBar.value >= maxTop || this.TopList.scrollBar.value <= 0) {
    //             tempTop = -tempTop;
    //         }
    //         this.BottomList.scrollBar.value += tempBtm;
    //         if (this.BottomList.scrollBar.value >= maxBtm || this.BottomList.scrollBar.value <= 0) {
    //             tempBtm = -tempBtm;
    //         }
    //     });
    // }

    GunGun() {
        var maxTop;
        var maxBtm;
        try {
            this.TopList.scrollBar.value = 0;
            this.BottomList.scrollBar.value = 0;
            maxTop = this.TopList.scrollBar.max;
            maxBtm = this.BottomList.scrollBar.max;
        } catch (error) {
            console.error(error);
            return;
        }
        var tempTop = 1;
        var tempBtm = 1;
        Laya.timer.frameLoop(1, this, () => {
            this.TopList.scrollBar.value += tempTop;
            if (this.TopList.scrollBar.value >= maxTop || this.TopList.scrollBar.value <= 0) {
                tempTop = -tempTop;
            }
            this.BottomList.scrollBar.value += tempBtm;
            if (this.BottomList.scrollBar.value >= maxBtm || this.BottomList.scrollBar.value <= 0) {
                tempBtm = -tempBtm;
            }
        });
    }
}