using FL.Battle;
using Spine.Unity;
using TMPro;
using UnityEngine;
using XGame.Framework.Map;
using XGame.Framework.ObjectCollection;
using XGame.Framework.Time;

namespace FL.Map
{
    public class PartnerEntityView : BattleEntityView<PartnerEntityVM>, IAttackContext, ISkillContext, ISpineContext
    {
        public void FindTarget(int skillId)
        {
            EventSingle.Instance.Notify(EventDefine.GameMainMapFindTarget, new FindTargetArgs()
            {
                entityId = Entity.EntityId,
                entityType = EEntityType.Monster,
                range = Entity.Attr.AtkRange,
                skillId = skillId,
            });
        }

        #region IAttackContext
        Transform IAttackContext.ActionRoot => VM.ActionRoot;
        //Vector3 IAttackHandle.Position => Position;
        ITimeModule IAttackContext.Time => Context.Time;
        SpineComponent IAttackContext.Spine => GetComponent<SpineComponent>();
        bool IAttackContext.IsPartnerAtk => true;// _entity.TableId == 20111 || _entity.TableId == 20551; // 单手剑||匕首
        #endregion
        #region ISkillContext
        ITimeModule ISkillContext.Time => Context.Time;
        #endregion

        #region ISpineContext
        SkeletonAnimation ISpineContext.Skeleton => null;
        ITimeModule ISpineContext.Time => Context.Time;
        #endregion

        protected override void OnEnable(object intent)
        {
        }
        protected override void OnDisable()
        {
            base.OnDisable();
        }
        protected override void OnStateChanged()
        {
            VM.NameText.text = Entity.Attr.Name;
            VM.StateText.text = Entity.State.ToString();
        }
    }

    public class PartnerEntityVM : EntityViewModel
    {
        public TextMeshPro StateText { get; private set; }
        public TextMeshPro NameText { get; private set; }
        public Transform ActionRoot { get; private set; }
        protected override void OnInit(IObjectCollector collector)
        {
            StateText = collector.GetComponent<TextMeshPro>("StateText");
            NameText = collector.GetComponent<TextMeshPro>("NameText");
            ActionRoot = collector.GetGameObject("ActionRoot").transform;
        }
    }
}
