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

public abstract class HandControl
{
	public enum ArrangeType
	{
		Fan,
		Flat
	}

	public enum HandState
	{
		Unfocus,
		Focus
	}

	public enum HandVisible
	{
		Invisible,
		Visible
	}

	protected readonly GameObject _gameObject;

	protected HandState _handState;

	protected HandVisible _handVisible;

	protected Vector3[] _cardPos;

	protected Vector3[] _cardRot;

	protected Vector3[] _cardScale;

	protected readonly BattleCamera _battleCamera;

	private HandTRSCalculatorBase _TRSCalculator;

	public Transform Transform { get; private set; }

	public bool IsHandStateLocked { get; private set; }

	public abstract Vector3 BaseHandPos { get; }

	public HandControl(GameObject gameObject, BattleCamera battleCamera)
	{
		_gameObject = gameObject;
		Transform = _gameObject.transform;
		Transform.localPosition = BaseHandPos;
		_handState = HandState.Unfocus;
		_handVisible = HandVisible.Invisible;
		_battleCamera = battleCamera;
		_cardPos = new Vector3[9];
		_cardRot = new Vector3[9];
		_cardScale = new Vector3[9];
		_TRSCalculator = CreateHandCardTRSCalculator(PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.FIXEDUSE_COST_INFO) ? ArrangeType.Flat : ArrangeType.Fan);
	}

	public void AttachCardView(IBattleCardView cardView)
	{
		if (!(cardView is NullBattleCardView))
		{
			cardView.Transform.parent = Transform;
			cardView.GameObject.SetActive(value: false);
			cardView.GameObject.SetActive(value: true);
		}
	}

	protected void RecalculateTRS(int cardNum)
	{
		for (int i = 0; i < cardNum; i++)
		{
			_TRSCalculator.CalcTRS(_handState, cardNum, i, ref _cardPos[i], ref _cardRot[i], ref _cardScale[i]);
		}
	}

	public void ChangeArrangeType(ArrangeType type, float time, List<IBattleCardView> battleCardViewList)
	{
		_TRSCalculator = CreateHandCardTRSCalculator(type);
		RearrangeHand(time, battleCardViewList);
	}

	protected abstract HandTRSCalculatorBase CreateHandCardTRSCalculator(ArrangeType type);

	public abstract void RearrangeHand(float time, List<IBattleCardView> battleCardViewList, bool isNewReplayMoveTurn = false);

	public abstract void HideHand(float time, List<IBattleCardView> battleCardViewList);

	public void LockHandControlState()
	{
		IsHandStateLocked = true;
	}

	public void SetHandState(HandState state)
	{
		if (!IsHandStateLocked)
		{
			_handState = state;
		}
	}

	public HandState GetHandState()
	{
		return _handState;
	}

	public bool IsHandStateFocus()
	{
		return _handState == HandState.Focus;
	}

	public HandVisible GetHandVisible()
	{
		return _handVisible;
	}

	public bool IsVisibleHand()
	{
		return _handVisible == HandVisible.Visible;
	}

	public Vector3 GetHandCardPos(int idx)
	{
		return _cardPos[idx];
	}

	public Vector3 GetHandCardRot(int idx)
	{
		return _cardRot[idx];
	}

	public void SetHandPosition()
	{
		Transform.localPosition = BaseHandPos;
	}
}
