using System;
using System.Collections.Generic;
using UnityEditor;

namespace UnityEngine.UI
{
    public class UGUITextTool
    {
        public static ITextTool TextTool;

        public interface IConfig
        {
            int GetID();
        }

        [Serializable]
        public struct LanguageChineseConfig : IConfig
        {
            public int GetID()
            {
                return ID;
            }

            /// <summary>
            ///ID
            /// </summary>
#if !COMBAT_SERVER
            public int ID;
#else
		public int ID{ set; get; }
#endif


            /// <summary>
            ///文本内容
            /// </summary>
#if !COMBAT_SERVER
            public string txt;
#else
		public string txt{ set; get; }
#endif
        }

        public class EditorLanguageChinese
        {
            public List<LanguageChineseConfig> configList = new List<LanguageChineseConfig>();

            public string Text(int id)
            {
                for (int i = 0; i < configList.Count; i++)
                {
                    if (configList[i].ID == id)
                    {
                        return configList[i].txt;
                    }
                }

                return "无";
            }
        }

        protected static EditorLanguageChinese editorLanguageChinese;
        protected static EditorLanguageChinese editorStartLanguageChinese;

        public static string GetLanguageMassage(int id)
        {
            if (!Application.isPlaying)
            {
#if UNITY_EDITOR


                editorStartLanguageChinese = new EditorLanguageChinese();
                TextAsset ta =
                    AssetDatabase.LoadAssetAtPath<TextAsset>(@"Assets\Res\Config\StartGameLanguageChineseConfig.json");
                if (ta != null)
                {
                    editorStartLanguageChinese = JsonUtility.FromJson<EditorLanguageChinese>(ta.text);
                }

                editorLanguageChinese = new EditorLanguageChinese();
                ta = AssetDatabase.LoadAssetAtPath<TextAsset>(@"Assets\Res\Config\LanguageChineseConfig.json");
                if (ta != null)
                {
                    editorLanguageChinese = JsonUtility.FromJson<EditorLanguageChinese>(ta.text);
                }

                if (editorStartLanguageChinese != null && editorStartLanguageChinese.Text(id) != "无")
                {
                    return editorStartLanguageChinese.Text(id);
                }
                else
                {
                    if (editorLanguageChinese != null)
                    {
                        return editorLanguageChinese.Text(id);
                    }
                }
#endif
            }
            else
            {
                return TextTool?.GetLanguageMassge(id);
            }

            return "无";
        }
    }
}