using System;
using UnityEngine;
// using FGUI.G002_main;
using Spine.Unity;
using DG.Tweening;

namespace ChillConnect
{
    public class StatementViewUI : BaseUI
    {
        private StatementViewUICtrl ctrl;
        private StatementViewModel model;
        private FGUI.Lobby_03.com_statement ui;
        private Action closeCallback;
        private Action open_sign;
        private bool is_get = false;
        public StatementViewUI(StatementViewUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.StatementViewUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "Lobby_03";
            uiInfo.assetName = "com_statement";
            uiInfo.layerType = UILayerType.Popup;
            uiInfo.isNeedOpenAnim = false;
            uiInfo.isNeedCloseAnim = false;
            uiInfo.isNeedUIMask = true;
        }

        #region 生命周期
        protected override void OnInit()
        {
            model = ModuleManager.Instance.GetModel(ModelConst.StatementViewModel) as StatementViewModel;
        }

        protected override void OnClose()
        {
            GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, true);
            
            //open_sign();

            if (GameHelper.IsShowOpenGameUI() &&HallManager.Instance.openTipsTimes == 1)
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
            }
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.Lobby_03.com_statement;
        }

        private bool need_show = false; 
        protected override void OnOpenBefore(object args)
        {
            HallManager.Instance.openTipsTimes++;
            
            GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, false);
  
            InitView();
        }

        protected override void OnOpen(object args)
        {
            //open_sign = (System.Action)args;
        }

        protected override void OnHide()
        {
        }

        protected override void OnDisplay(object args)
        {
        }
        #endregion

        #region 消息
        protected override void AddListener()
        {

        }
        protected override void RemoveListener()
        {

        }
        #endregion

        
        //初始化页面逻辑
        private void InitView()
        {
            ui.list.scrollPane.onScrollEnd.Add(OnListScroll);
            ui.btn_back.SetClick(CtrlCloseUI);
        }
        
        private void OnListScroll()
        {
            var pageIndex = ui.list.scrollPane.currentPageX;
            
            if (pageIndex == 0)
            {
                ui.state1.state.selectedIndex = 1;
                ui.state2.state.selectedIndex = 0;
            }else if (pageIndex == 1)
            {
                ui.state1.state.selectedIndex = 0;
                ui.state2.state.selectedIndex = 1;
            }
        }
    }
}