using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

namespace MyGame.Scripts
{
    public class VideoFailToLoadDialog : MonoBehaviour
    {
        private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger");
        private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger");

        [SerializeField] private Animator backgroundAnimator;
        [SerializeField] private Button closeButton;

        private void Start()
        {
            closeButton.OnClickAsObservable().Take(1).Subscribe(_ =>
            {
                transform.parent.SetLocalScale(0);
                backgroundAnimator.SetTrigger(CloseTrigger);
                this.CallWaitForSeconds(.25f, () =>
                {
                    TransitionManager.Instance.UnloadScene(GameScenes.WatchMovieFailure);
                });
            }).AddTo(this);
        }
    }
}