using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AnimationFunctions : MonoBehaviour
{
    private GameData _gameData;
    private SetGameObjects _gameObjectsSetter;
    private AudioSource _audioSource;

    private Dictionary<string, AudioClip> _audioClips;

    public void Awake()
    {
        _gameData = GameObject.Find("GameState").GetComponent<GameData>();
        _gameObjectsSetter = GameObject.Find("GameState").GetComponent<SetGameObjects>();
        _audioSource = GetComponent<AudioSource>();

        _audioClips = new Dictionary<string, AudioClip>();
        _audioClips.Add("Chant", Resources.Load<AudioClip>("Audio/Chant2"));
        _audioClips.Add("FeatsOfStrength", Resources.Load<AudioClip>("Audio/FeatsOfStrength"));
        _audioClips.Add("Break", Resources.Load<AudioClip>("Audio/Break"));
        _audioClips.Add("BasicMath", Resources.Load<AudioClip>("Audio/BasicMath"));
        _audioClips.Add("AvB", Resources.Load<AudioClip>("Audio/WhichIsBetter"));
        _audioClips.Add("Trivia", Resources.Load<AudioClip>("Audio/Smart"));
    }

	public void NextActivity()
    {
        SceneManager.LoadScene("Gameplay");
    }

    public void NextActivityIfNoFollowupText()
    {
        if (!_gameData.HasFollowupText())
            SceneManager.LoadScene("Gameplay");
    }

    public void DeactiveTimerIfNoFollowupText()
    {
        if (!_gameData.HasFollowupText())
            _gameObjectsSetter.DeactiveTimer();
    }

    public void PlayChant()
    {
        _audioSource.PlayOneShot(_audioClips["Chant"]);
    }

    public void PlayTitleVoiceover()
    {
        string clipName = null;

        switch (_gameData.CurrentActivity.activityType)
        {
            case DataImport.ActivityType.FeatsOfStrength:
                clipName = "FeatsOfStrength";
                break;
            case DataImport.ActivityType.Break:
                clipName = "Break";
                break;
            case DataImport.ActivityType.BasicMath:
                clipName = "BasicMath";
                break;
            case DataImport.ActivityType.AvB:
                clipName = "AvB";
                break;
            case DataImport.ActivityType.Trivia:
                clipName = "Trivia";
                break;
        }

        if (clipName != null)
            _audioSource.PlayOneShot(_audioClips[clipName]);
    }
}
