using System;
using DG.Tweening;
using FairyGUI;
using FGUI.Login_05;
using SGModule.Net;
using SGModule.NetKit;
using Spine.Unity;

namespace ChillConnect
{
    // using FGUI.A000_common;

    public class GameLoginUI : BaseUI
    {
        private GameLoginUICtrl ctrl;
        private GameLoginModel model;
        private com_login_page ui;

        public GameLoginUI(GameLoginUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.GameLoginUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "Login_05";
            uiInfo.assetName = "com_login_page";
            uiInfo.layerType = UILayerType.Normal;
        }

        protected override void OnInit()
        {
        }

        protected override void OnClose()
        {
            netFbloadBindLogin?.Kill();
            CommonHelper.FadeOut(ui);
            UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenBgUI_Close);
        }

        protected override void OnBind()
        {
            ui = baseUI as com_login_page;
        }

        protected override void OnOpenBefore(object args)
        {
            TrackKit.TrackLoginFunnel(LoginFunnelEventType.EnterButtonShow);

            InitView();
        }

        protected override void OnOpen(object args)
        {
            CommonHelper.FadeIn(ui);
        }

        protected override void AddListener()
        {
        }

        protected override void RemoveListener()
        {
        }

        private void InitView()
        {



            ui.btn_login.SetClick(OnClickBtn, true);

            App.HideLoadingUI();
            ui.text_privacy_user.text_privacy_user.SetClick(OnClickPrivacy);
            ui.text_privacy_user.text_privacy_user.onClickLink.Add(content =>
            {
                switch (content.data)
                {
                    case "link_href":
                        OnClickTerms();
                        break;
                    case "link_href1":
                        OnClickPrivacy();
                        break;
                }
            });


            // Action closeCallback = null;
            // var meteor = FXManager.Instance.SetFx<SkeletonAnimation>(ui.pla1, Fx_Type.meteor, ref closeCallback);
            // meteor.state.SetAnimation(0, "liziguang1", true);

            // var login = FXManager.Instance.SetFx<SkeletonAnimation>(ui.pla, Fx_Type.login, ref closeCallback);
            // login.state.SetAnimation(0, "animation", true);

            // var lantern = FXManager.Instance.SetFx<SkeletonAnimation>(ui.pla1, Fx_Type.lantern, ref closeCallback);
            // lantern.state.SetAnimation(0, "deng", true);

            ui.btn_space.SetClick(OnclickSpace);
            ui.btn_error.SetClick(OnClickError);
            ui.lab_int.text = "int:" + MaxADKit.interstitialADUnitID;
            ui.lab_reward.text = "reward:" + MaxADKit.rewardedADUnitID;
            ui.lab_key.text = "sdkKey:" + MaxADKit.SDKKey;
#if GAME_RELEASE
            ui.btn_space.visible = false;
            ui.btn_error.visible = false;
            ui.lab_int.visible = false;
            ui.lab_reward.visible = false;
            ui.lab_key.visible = false;
#endif
        }
        private void OnclickSpace()
        {
            // Debug.Log("OnclickSpace");
#if !UNITY_EDITOR
            MaxSdk.ShowMediationDebugger();
#endif
        }
        int[] test = new int[5];
        private void OnClickError()
        {
            int[] test = new int[1];
            test[0] = 1;
            test[5] = 0;
        }

        private Tween netFbloadBindLogin;

        public void OnClickBtn()
        {
            TrackKit.TrackLoginFunnel(LoginFunnelEventType.EnterButtonClick);

            CtrlDispatcher.Instance.Dispatch(CtrlMsg.Game_Start);
            CtrlCloseUI();
        }

        private void OnClickPrivacy()
        {
            UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, 0);
        }

        private void OnClickTerms()
        {
            UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, 1);
        }
    }
}
