using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;

public class Diary : MonoBehaviour {

    public static Diary instance;

    public AudioMixer mainMixer;
    public Animator diaryAnim;

    private bool sfxMuted;
    private bool musicMuted;

    private float TimeSinceLastAction;
    public bool isActive 
    {
        get
        {
            return ( Time.unscaledTime - TimeSinceLastAction > 0.3f );
        }
    }

    private void Awake ()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }
    }

    public void setShowing (bool setShowing)
    {
        if (diaryAnim != null)
        {
            if (diaryAnim.GetBool("InMenu") != setShowing)
            {
                TimeSinceLastAction = Time.unscaledTime;
                diaryAnim.SetBool("InMenu", setShowing);
                Time.timeScale = ( setShowing ) ? 0f : 1f;
                if (setShowing)
                {
                    AudioManager.instance.Play("instructions_open");
                }
                else
                {
                    AudioManager.instance.Play("instructions_close");
                }
            }
        }
    }

    public void returnToGamePressed ()
    {
        CursorBehaviour.instance.setCurrentState(GameState.handFree);
        setShowing(false);
    }

    public void restartGamePressed ()
    {
        CursorBehaviour.instance.setCurrentState(GameState.handFree);
        setShowing(false);
        IncomingConnectionController.instance.currentlyRunningLevel = 0;
        IncomingConnectionController.instance.RunNextLevel();
    }

    public void quitGamePressed ()
    {
        Application.Quit();
    }
    
    
    public void MusicMute ()
    {
        musicMuted = !musicMuted;
        mainMixer.SetFloat("MusicVolume", ( musicMuted ) ? -80f : 0f);
    }
    
    public void SFXMute ()
    {
        sfxMuted = !sfxMuted;
        mainMixer.SetFloat("SFXVolume", ( musicMuted ) ? -80f : 0f);
    }
}
