using Camera;
using UnityEngine;

namespace Animations
{
	public class TransitionController : MonoBehaviour
	{
		[SerializeField] private CameraManager cameraManager;
		[SerializeField] private Transform transitionObject;
		[SerializeField] private Animator animator;
		[SerializeField] private Material material;
		
		private static readonly int OpenAnimation = Animator.StringToHash("Open");

		private void Start()
		{
			transitionObject.localPosition = new Vector3(-cameraManager.GameCamera.orthographicSize * cameraManager.GameCamera.aspect * 0.5f,
				0, 
				0);
			transitionObject.localScale = new Vector3(cameraManager.GameCamera.orthographicSize * cameraManager.GameCamera.aspect,
				cameraManager.GameCamera.orthographicSize,
				1f);
		}

		public void Open(Color color)
		{
			material.color = cameraManager.GameCamera.backgroundColor;
			animator.SetTrigger(OpenAnimation);
		}
	}
}