using System;
using FGUI.Arrow_game;
using FGUI.Arrow_Theme;

namespace ChillConnect
{
    public class ArrowThemeUI : BaseUI
    {
        private ArrowThemeUICtrl ctrl;
        private ArrowThemeModel model;
        private com_theme ui;
        
        private Action closeCallback;
        

        public ArrowThemeUI(ArrowThemeUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.ArrowThemeUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期

        protected override void OnInit()
        {
            //model = ModuleManager.Instance.GetModel(ModelConst.GameResultModel) as GameResultModel;
        }

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

        }
        //
        protected override void OnBind()
        {
            ui = baseUI as com_theme;
        }
        private SuccessData successData_;

        protected override void OnOpenBefore(object args)
        {
            GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, false);
            
            ui.btn_switch.state.selectedIndex = DataMgr.ArrowDarkTheme.Value;
            SetBtnState();

            ui.btn_dark.SetClick(() => { SetBtnClick(0); });
            // ui.btn_worm.SetClick(() => { SetBtnClick(1); });
            ui.btn_colours.SetClick(() => { SetBtnClick(2); });


            ui.btn_switch.SetClick(() =>
            {
                if (DataMgr.ArrowDarkTheme.Value == 0)
                {
                    DataMgr.ArrowDarkTheme.Value = 1;
                }
                else
                {
                    DataMgr.ArrowDarkTheme.Value = 0;
                }
                
                ui.btn_switch.state.selectedIndex = DataMgr.ArrowDarkTheme.Value;
                
                GameDispatcher.Instance.Dispatch(GameMsg.ThemeChange);
                
            });
            
            ui.btn_close.SetClick(() =>
            {
                CtrlCloseUI();
            });
        }
        
        private void SetBtnClick(int index)
        { 
            DataMgr.ArrowTheme.Value = index;
            SetBtnState();
            
            GameDispatcher.Instance.Dispatch(GameMsg.ThemeChange);
        }

        private void SetBtnState()
        {
            switch (DataMgr.ArrowTheme.Value)
            {
                case 0:
                    ((btn_green)ui.btn_dark).touchable = false;
                    ((btn_green)ui.btn_worm).touchable = true;
                    ((btn_green)ui.btn_colours).touchable = true;
                    ((btn_green)ui.btn_dark).state.selectedIndex = 0;
                    ((btn_green)ui.btn_worm).state.selectedIndex = 1;
                    ((btn_green)ui.btn_colours).state.selectedIndex = 1;
                    break;
                case 1:
                    ((btn_green)ui.btn_dark).touchable = true;
                    ((btn_green)ui.btn_worm).touchable = false;
                    ((btn_green)ui.btn_colours).touchable = true;
                    ((btn_green)ui.btn_dark).state.selectedIndex = 1;
                    ((btn_green)ui.btn_worm).state.selectedIndex = 0;
                    ((btn_green)ui.btn_colours).state.selectedIndex = 1;
                    break;
                case 2:
                    ((btn_green)ui.btn_dark).touchable = true;
                    ((btn_green)ui.btn_worm).touchable = true;
                    ((btn_green)ui.btn_colours).touchable = false;
                    ((btn_green)ui.btn_dark).state.selectedIndex = 1;
                    ((btn_green)ui.btn_worm).state.selectedIndex = 1;
                    ((btn_green)ui.btn_colours).state.selectedIndex = 0;
                    break;
            }
        }

        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

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

        #region 消息
        protected override void AddListener()
        {
        }
        protected override void RemoveListener()
        {
        }
        #endregion
        private int time_count;
       
    }
}
