using System.Collections.Generic;
using Managers;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

namespace DialogueSystem.Notes
{
    /// <summary>
    /// 
    /// Notes can not be collected anymore (old version).
    /// The only note that can be found is in the intro scene.
    /// 
    /// </summary>
    public class Note : MonoBehaviour
    {
        // whenever the player clicks on it then we open the window with the specified information from the note
        public NoteScriptableObject noteSO;

        public List<NoteScriptableObject> allNotes;
        
        public GameObject noteWithoutAnimation;
        public GameObject noteWithAnimation;
        
        private void Start()
        {
            int completedLevel = GlobalData.lastCompletedLevel;
            noteSO = allNotes[completedLevel];
            
            this.OnMouseDownAsObservable()
                .Subscribe(_ =>
                {
                    OnNoteClicked();
                })
                .AddTo(this);

            this.OnMouseEnterAsObservable()
                .Subscribe(_ =>
                {
                    OnNoteEnter();
                })
                .AddTo(this);


            this.OnMouseExitAsObservable()
                .Subscribe(_ =>
                {
                    OnNoteExit();
                })
                .AddTo(this);
        }

        private void OnNoteClicked()
        {
            Debug.Log("On Mouse Clicked");
            // GenericScriptableObjectArchive.AddToArchive(noteSO, "Note", transform.position);
            DialogueManager.Instance.OpenNoteWindow(noteSO);
        }

        private void OnNoteEnter()
        {
            noteWithoutAnimation.SetActive(false);
            noteWithAnimation.SetActive(true);
        }

        private void OnNoteExit()
        {
            noteWithoutAnimation.SetActive(true);
            noteWithAnimation.SetActive(false);
        }
        
    }
}
