using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Wizard.Battle.View;
using Wizard.Battle.View.Vfx;

public abstract class InPlayViewBase
{
	protected readonly InPlayCardControl inPlayCardControl;

	protected readonly List<IBattleCardView> battleCardViewList;

	public InPlayViewBase()
	{
	}

	public InPlayViewBase(GameObject inPlayGameObject)
	{
		inPlayCardControl = new InPlayCardControl(inPlayGameObject);
		battleCardViewList = new List<IBattleCardView>();
	}

	protected abstract void RearrangeInplay(float rearrangeTime);

	public VfxBase OneTimeRearrangeInplay(float rearrangeTime)
	{
		if (BattleManagerBase.GetIns().IsRecovery)
		{
			rearrangeTime = 0f;
		}
		return InstantVfx.Create(delegate
		{
			RearrangeInplay(rearrangeTime);
		});
	}

	public void AddCardToView(IBattleCardView cardViewToAdd, float deckRearrangeTime)
	{
		if (BattleManagerBase.GetIns().IsRecovery)
		{
			deckRearrangeTime = 0f;
		}
		if (!battleCardViewList.Contains(cardViewToAdd))
		{
			battleCardViewList.Add(cardViewToAdd);
			RearrangeInplay(deckRearrangeTime);
		}
	}

	public void AddCardsToView(List<IBattleCardView> cardViewsToAdd, float deckRearrangeTime)
	{
		if (BattleManagerBase.GetIns().IsRecovery)
		{
			deckRearrangeTime = 0f;
		}
		List<IBattleCardView> source = cardViewsToAdd.FindAll((IBattleCardView cardView) => !battleCardViewList.Contains(cardView));
		if (source.Any())
		{
			battleCardViewList.AddRange(source.ToList());
			RearrangeInplay(deckRearrangeTime);
		}
	}

	public virtual void RemoveCardFromView(IBattleCardView cardViewToRemove, float deckRearrangeTime)
	{
		if (BattleManagerBase.GetIns().IsRecovery)
		{
			deckRearrangeTime = 0f;
		}
		if (battleCardViewList.Remove(cardViewToRemove))
		{
			RearrangeInplay(deckRearrangeTime);
		}
	}

	public virtual void RemoveCardFromView(IBattleCardView cardViewToRemove)
	{
		battleCardViewList.Remove(cardViewToRemove);
	}

	public virtual void RemoveCardsFromView(List<IBattleCardView> cardViewsToRemove, float deckRearrangeTime)
	{
		if (BattleManagerBase.GetIns().IsRecovery)
		{
			deckRearrangeTime = 0f;
		}
		if (cardViewsToRemove.FindAll((IBattleCardView cardView) => battleCardViewList.Remove(cardView)).Any())
		{
			RearrangeInplay(deckRearrangeTime);
		}
	}

	public virtual VfxBase CreateRemoveCardsFromViewVfx(List<IBattleCardView> cardViewsToRemove, float deckRearrangeTime)
	{
		return InstantVfx.Create(delegate
		{
			RemoveCardsFromView(cardViewsToRemove, deckRearrangeTime);
		});
	}

	public void Replacement(IBattleCardView originalView, IBattleCardView newView)
	{
		battleCardViewList.Insert(battleCardViewList.IndexOf(originalView), newView);
		battleCardViewList.RemoveAt(battleCardViewList.IndexOf(originalView));
		if (BattleManagerBase.GetIns().IsRecovery)
		{
			RearrangeInplay(0f);
		}
		else
		{
			RearrangeInplay(0.1f);
		}
	}

	public void AttachCardView(IBattleCardView cardView)
	{
		cardView.Transform.parent = inPlayCardControl.transform;
	}

	public int GetViewIndex(IBattleCardView viewCard)
	{
		return battleCardViewList.IndexOf(viewCard);
	}

	public Vector3 GetPositionInView(IBattleCardView battleCardView, bool isGlobal)
	{
		int viewIndex = GetViewIndex(battleCardView);
		return GetPositionInView(viewIndex, isGlobal);
	}

	public Vector3 GetPositionInView(int viewIndex, bool isGlobal)
	{
		Vector3 vector = inPlayCardControl.GetPosition(viewIndex);
		if (isGlobal)
		{
			vector = inPlayCardControl.transform.TransformPoint(vector);
		}
		return vector;
	}

	public Vector3 GetPositionInOverflowList(int indexInOverflowList, bool isPlayer)
	{
		return inPlayCardControl.GetOverflowPosition(indexInOverflowList, isPlayer);
	}
}
