using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace TFramework
{
    [Serializable]
    public class UIBehaviour : Behaviour
    {
        private RectTransform _rt;

        /// <summary>
        /// 启用动画
        /// </summary>
        [SerializeField]
        private bool enableAnim = false;

        
        public string m_uiAnimType;

        private UIAnimBase uIAnim;

        public RectTransform rectTransform => _rt = _rt ?? GetComponent<RectTransform>();

        public bool IsEnableAnim
        {
            get
            {
                if (enableAnim)
                {
                    if (uIAnim == null)
                        uIAnim = GlobalTool.CretaInstanceToCurrentDomain<UIAnimBase>(m_uiAnimType);
                }
                return enableAnim;
            }
            set
            {
                enableAnim = value;
            }
        }

        [SerializeField]
        private bool isScriptUse;
        [SerializeField]
        private List<VariableInfo> variableInfos;
        [SerializeField]
        private string parnetPanel;

        [SerializeField]
        private List<UseResInfo> useResInfos;

        public override void Start()
        {
            base.Start();
        }

        private void OnEnable()
        {
            if (IsEnableAnim)
                uIAnim.EnableAnim(rectTransform);
        }

        private void OnDisable()
        {
            if (IsEnableAnim)
                uIAnim.DisableAnim(rectTransform);
        }

        public UnityEngine.Object GetRes(string resName)
        {
            return useResInfos.Find(p => p.resName.Equals(resName))?.resObj;
        }


        #region Text
 
        /// <summary>
        /// 获取TextPro文本在本地化语言配置表的编号
        /// </summary>
        /// <returns></returns>
        public int GetLanguageId()
        {
            Text text = GetComponent<Text>();
            if (text)
                return (text as LocalizedLanguageText) == null ? -1 : (text as LocalizedLanguageText).lacalizedLanguageId;
            else
                return -1;
        }
        #endregion
    }

    [Serializable]
    public class VariableInfo
    {
        public string variableName;
        public string compentType;
    }

    [Serializable]
    public class UseResInfo
    {
        public UnityEngine.Object resObj;
        public string resName;
    }
}
