using UnityEngine;
using UnityEngine.SceneManagement;

public class IntroDoor : MonoBehaviour
{
    public GameObject promptBeforeOpen;
    public GameObject promptAfterOpen;
    private bool isOpen = false;
    public string nextSceneName = "IntroScene";

    private AudioSource audioSource;

    void Awake()
    {
        audioSource = GetComponent<AudioSource>();
    }

    void OnMouseEnter()
    {
        if(!UIManagerIntro.Instance.GetIsPaused())
        {
            if (isOpen)
            {
                if (promptAfterOpen)
                    promptAfterOpen.SetActive(true);
            }
            else
            {
                if (promptBeforeOpen)
                    promptBeforeOpen.SetActive(true);
            }
        }
    }

    void OnMouseExit()
    {
        if (!UIManagerIntro.Instance.GetIsPaused())
        {
            if (isOpen)
            {
                if (promptAfterOpen)
                    promptAfterOpen.SetActive(false);
            }
            else
            {
                if (promptBeforeOpen)
                    promptBeforeOpen.SetActive(false);
            }
        }
    }

    void OnMouseDown()
    {
        if (!UIManagerIntro.Instance.GetIsPaused())
        {
            if (!isOpen)
            {
                // Knock
                Debug.Log("Knocking!");
                if (audioSource)
                    audioSource.Play();
            }
            else
            {
                // Enter door
                SceneManager.LoadScene(nextSceneName);
            }
        }
    }

    public void SetOpen(bool open)
    {
        isOpen = open;
    }
}