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

public class GameGuideDialog : MonoBehaviour
{
    private static readonly string CallbackTag = "GameGuideDialogCallback";
    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.SetLocalScale(0);
            backgroundAnimator.SetTrigger(CloseTrigger);
            this.CallWaitForSeconds(.25f, () =>
            {
                LocalCacheManager.Load<Action>(CallbackTag, null)?.Invoke();
                LocalCacheManager.Remove(CallbackTag);
                TransitionManager.Instance.UnloadScene(GameScenes.FryingPanExplanation); 
            });
        }).AddTo(this);
    }

    public static void ShowDialog(Action onClose = null)
    {
        LocalCacheManager.Save(CallbackTag, onClose);
        TransitionManager.Instance.LoadSceneAdditive(GameScenes.FryingPanExplanation);
    }
}
