using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class OptionsController : MonoBehaviour {

    public Slider[] volumeSliders;

    public AudioManager audioManager;

    public TMP_InputField moodleUsernameInput;

    private void Start() {

        if (volumeSliders.Length >= 2) {

            if(volumeSliders[0] != null)
                volumeSliders[0].value = audioManager.GetVolume(AudioManager.AudioChannel.Music);

            if(volumeSliders[1] != null)
                volumeSliders[1].value = audioManager.GetVolume(AudioManager.AudioChannel.SoundEffects);
        }
    }
    public void SetAudioVolume(int source)
    {
        if (source == 0)
        {
            audioManager.SetVolume(volumeSliders[source].value, AudioManager.AudioChannel.Music);
            PlayerPrefs.SetFloat("MusicVolume", volumeSliders[source].value);
        }
        else if (source == 1) {
            audioManager.SetVolume(volumeSliders[source].value, AudioManager.AudioChannel.SoundEffects);
            PlayerPrefs.SetFloat("SoundEffectsVolume", volumeSliders[source].value);
        }
    }

    public void UpdateMoodleUsername() {
        string moodleUsername = moodleUsernameInput.text;
        if (moodleUsername.Length > 0) {
            PlayfabCloudScriptAPI.UpdatePlayerMoodleData(moodleUsername);
        }
    }
}
