using System;
using Fort23.Core;
using Fort23.UTool;
using UnityEngine;

namespace Fort23.Mono
{
    public class UIComponent : UIBase, IGObjectPoolInterface
    {
        private bool _isActivePool;

        public virtual async void Show()
        {
            await base.Show();
        }

        public virtual void Close()
        {
        }

        public string poolObjName { get; set; }
        public bool isUse { get; set; }
        public bool isDestroy { get; }
        public AssetHandle AssetHandle { get; set; }
        public TimerEntity DestroyTimer { get; set; }

        public GameObject own
        {
            get { return _own; }
        }

        private GameObject _own;

        public virtual void ResetData()
        {
        }

        /// <summary>
        /// 池子激活的时候
        /// </summary>
        public virtual void ActiveObj()
        {
            _isActivePool = true;
            own.SetActive(true);
        }

        /// <summary>
        /// 对方放回池子的时候
        /// </summary>
        public virtual void DormancyObj()
        {
            own.SetActive(false);
            if (!_isActivePool)
            {
                return;
            }

            DelEvent();
        }

        public void SetPosition(Vector3 pos)
        {
#if !COMBAT_SERVER
            _own.transform.position = pos;
#endif
        }

        public void SetScale(Vector3 scale)
        {
#if !COMBAT_SERVER
            _own.transform.localScale = scale;
#endif
        }

        public void SetRotation(Vector3 rotation)
        {
#if !COMBAT_SERVER
            _own.transform.eulerAngles = rotation;
#endif
        }

        public Vector3 GetPosition()
        {
            throw new System.NotImplementedException();
        }

        public Vector3 GetScale()
        {
            throw new System.NotImplementedException();
        }

        public Vector3 GettRotation()
        {
            throw new System.NotImplementedException();
        }

        public void SetActive(bool isActive)
        {
#if !COMBAT_SERVER
            _own.SetActive(isActive);
#endif
        }

        public async CTask DelayHide()
        {
        }

        /// <summary>
        /// 对象被销毁的时候
        /// </summary>
        public virtual void DestroyObj()
        {
            if (!_isActivePool)
            {
                return;
            }

            DelEvent();
        }

        public virtual void Preset()
        {
        }

        public virtual void AddEvent()
        {
        }


        public virtual void DelEvent()
        {
        }


        public void SetGameObject(GameObject gameObject)
        {
            _own = gameObject;
        }


       
    }
}