using System;
using System.Collections.Generic;
using SGModule.MarkdownKit;
using SGModule.NetKit;
using RedHotRoast;
using SGModule.Common.Helper;
using UnityEngine;

public class LoveLegendRoot : MonoBehaviour
{
    public void Awake()
    {
#if !UNITY_EDITOR || GAME_RELEASE
        GameObject.Find("IngameDebugConsole").SetActive(true);
#endif
        MaxADKit.Init();
        // SGModule.Net.NetworkKit.Instance.InitData(NetworkManager.identifier,true);
        OnLauncher();
        TrackKit.TrackLoginFunnel(LoginFunnelEventType.Bootstrap);

        BuildGMTool();
        NetGmTool.Instance.Init();
    }

    public static void OnLauncher()
    {
        Language.LoadLocalizedText();
        Language.Initialize();
        AppObjConst.FrameGo = new GameObject($"{AppObjConst.FrameGoName}");
        AppObjConst.FrameGo.AddComponent<LoveLegendCore>();
        DontDestroyOnLoad(AppObjConst.FrameGo);
        App.InitApplication(SuperApplication.Instance);



        // MarkdownKit.Instance.LoadText("privacy", "https://www.dreamlovelegend.com/privacy.md");
        // MarkdownKit.Instance.LoadText("user", "https://www.dreamlovelegend.com/user.md");
    }

    private static string adInfoLabel = "";
    private static void BuildGMTool()
    {
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Separator, () => "测试工具"));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Separator, () => "测试工具"));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "清空签到记录",
            s =>
            {
                DataMgr.SignState.Value = new List<long>();
            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "测试签到",
            s =>
            {
                DataMgr.SignState.Value.Add(GameHelper.GetNowTime() + (long)TimeSpan.FromDays(DataMgr.SignState.Value.Count).TotalSeconds);
                DataMgr.SignState.Save();
            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "打开礼包界面",
            s =>
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PackrewardUI_Open, true);
            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "加广告次数+1",
            s =>
            {
                var adNums = AdExchangeManager.Instance.GetLookRewardADNum();
                adNums += 1;
                AdExchangeManager.Instance.SetLookRewardADNum(adNums);
            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "加广告次数+10",
            s =>
            {
                var adNums = AdExchangeManager.Instance.GetLookRewardADNum();
                adNums += 10;
                AdExchangeManager.Instance.SetLookRewardADNum(adNums);
            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "类型测试+10",
            s =>
            {
                DataMgr.Ticket.Value += 10;
            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "客户端日志上传",
            s =>
            {
                // ErrorLogKit.Send("error", "客户端日志上传", "GM工具点击测试",SuperApplication.Instance.attribution);

            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button,
            () => "广告ID信息打印",
            s =>
            {
                adInfoLabel += $"Max token: {MaxADKit.SDKKey} \n 激励广告Id: {MaxADKit.rewardedADUnitID} \n 插屏广告Id: {MaxADKit.interstitialADUnitID} \n";

            }));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Button, () => "关卡+1",
            s =>
            {
                DataMgr.GameLevel.Value = DataMgr.GameLevel.Value + 1;
            }));
        // 输入设置等级
        GMTool.Instance.AddItem(new GMToolItem(
            GUIType.InputField,
            () => "设置等级",
            s =>
            {
                if (int.TryParse(s, out int level))
                {
                    DataMgr.GameLevel.Value = level;
                    adInfoLabel += $"手动设置等级 = {level}\n";

                    // 如果需要额外刷新，例如保存一下等级（可选）
                    DataMgr.GameLevel.Save();
                }
                else
                {
                    adInfoLabel += $"等级输入错误：{s}\n";
                }
            }
        ));
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Label, () => $"{DataMgr.Ticket} 类型测试"));
        // 来显示 adInfoLabel 的内容
        GMTool.Instance.AddItem(new GMToolItem(GUIType.Label, () => adInfoLabel));
        GMTool.Instance.AddItem(new GMToolItem(
            GUIType.InputField,
            () => "设置等级",
            s =>
            {
                if (int.TryParse(s, out int level))
                {
                    DataMgr.GameLevel.Value = level;
                    adInfoLabel += $"手动设置等级 = {level}\n";

                    // 如果需要额外刷新，例如保存一下等级（可选）
                    DataMgr.GameLevel.Save();
                }
                else
                {
                    adInfoLabel += $"等级输入错误：{s}\n";
                }
            }
        ));

    }
}
