using System;
using UnityEngine;
using mgaia.Utils;
using mgaia.Utils.Animations;

public class LetterAndFrameContainer : MonoBehaviour
{
    private bool mIsAnimating = false;
    private float mScreenHeight;
    private Action mOnArrive;

    private void Awake()
    {
        Camera camera = gameObject.GetParentCamera();
        mScreenHeight = camera.GetOrtographicDrawingSize().y;
    }

    public void Run(LetterAndFrameAnimations animation, Action onArrive)
    {
        Assert.AssertTrue(!mIsAnimating, "Já está rodando uma animação no LetterAndFrameContainer!");

        mOnArrive = onArrive;

        mIsAnimating = true;

        GameobjectPositionIncrementAnimation positionAnimation = new GameobjectPositionIncrementAnimation(
            new float[] { GameConstants.LETTER_AND_FRAME_SLIDING_TIME },
            new ValueType[] { new Vector3(0, (animation == LetterAndFrameAnimations.ShowHall ? -mScreenHeight : mScreenHeight), 0) }, 
            Vector3.zero, 
            false);
        positionAnimation.AnimationEnded += OnAnimationEnded;

        CodeAnimationManager.Instance.ActivateAnimation(positionAnimation, new[] { gameObject });
    }

    private void OnAnimationEnded(object sender, AbstractCodeAnimation.AnimationEndedEventArgs e)
    {
        mIsAnimating = false;

        mOnArrive();
        mOnArrive = null;
    }
}