using IgnoreOPS;

namespace ChillConnect
{
    public class RewardUICtrl : BaseUICtrl
    {
        private RewardUI ui;
        private RewardModel model;

        private uint openUIMsg = UICtrlMsg.RewardUI_Open;
        private uint closeUIMsg = UICtrlMsg.RewardUI_Close;

        public RewardData rewardInfo;

        protected override void OnInit()
        {
        }

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {

                if (args != null)
                {
                    rewardInfo = (RewardData)args;
                }


                ui = new RewardUI(this);
                ui.Open(args);
            }
        }

        public override void CloseUI(object args = null)
        {
            if (ui is { isClose: false })
            {
                ui.Close();
            }

            ui = null;
        }

        public override uint GetOpenUIMsg(string uiName)
        {
            return openUIMsg;
        }

        public override uint GetCloseUIMsg(string uiName)
        {
            return closeUIMsg;
        }

        public void GetReward(int rate = 1)
        {
            foreach (var rewardSingleData in rewardInfo.GetRewardDataList())
            {
                rewardSingleData.rate = rate;
            }
            // if (rewardInfo.sign_in_days == 1)
            // {

            //     // setItemUrl(ui.loader_icon0, ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].rewards_type[1]);
            //     // ui.text_num1.text = "x" + ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1];

            //     if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].rewards_type[1] == 2)
            //     {
            //         // PlayerPrefs.SetInt("_back", PlayerPrefs.GetInt("_back", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1]);
            //         SaveData.GetSaveObject().item_back_num += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1];
            //     }
            //     else if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].rewards_type[1] == 1)
            //     {
            //         // PlayerPrefs.SetInt("_out", PlayerPrefs.GetInt("_out", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1]);
            //         SaveData.GetSaveObject().item_out_num += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1];
            //     }
            //     else if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].rewards_type[1] == 3)
            //     {
            //         //  PlayerPrefs.SetInt("_refresh", PlayerPrefs.GetInt("_refresh", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1]);
            //         SaveData.GetSaveObject().item_refresh_num += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[1].quantity[1];
            //     }
            //     GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);

            // }
            // else
            if (rewardInfo.sign_in_days == 6)
            {
                if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].rewards_type[1] == 2)
                {
                    //  PlayerPrefs.SetInt("_back", PlayerPrefs.GetInt("_back", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[1]);
                    SaveData.GetSaveObject().BackPropNum += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[1];
                }
                else if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].rewards_type[1] == 1)
                {
                    //  PlayerPrefs.SetInt("_out", PlayerPrefs.GetInt("_out", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[1]);
                    SaveData.GetSaveObject().OutPropNum += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[1];
                }
                else if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].rewards_type[1] == 3)
                {
                    //  PlayerPrefs.SetInt("_refresh", PlayerPrefs.GetInt("_refresh", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[1]);
                    SaveData.GetSaveObject().RefreshPropNum += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[1];
                }
            }

            // if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].rewards_type[2] == 2)
            // {
            //     //  PlayerPrefs.SetInt("_back", PlayerPrefs.GetInt("_back", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[2]);
            //     SaveData.GetSaveObject().item_back_num += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[2];
            // }
            // else if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].rewards_type[2] == 1)
            // {
            //     //  PlayerPrefs.SetInt("_out", PlayerPrefs.GetInt("_out", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[2]);
            //     SaveData.GetSaveObject().item_out_num += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[2];
            // }
            // else if (ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].rewards_type[2] == 3)
            // {
            //     //  PlayerPrefs.SetInt("_refresh", PlayerPrefs.GetInt("_refresh", 0) + rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[2]);
            //     SaveData.GetSaveObject().item_refresh_num += rate * (int)ConfigSystem.GetConfig<SignDailyRewardModel>().DataList[6].quantity[2];
            // }

            GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
            RewardSystem.GetReward(rewardInfo);
        }

        protected override void AddListener()
        {
            uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
        }

        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
        }
    }
}