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

public class MainMenuController : MonoBehaviour
{
    public List<CanvasGroup> canvasGroups;
    public float animSpeed = 3.0f;

    public CanvasGroup activeModal;

    public DifficultySetting smallDifficulty;
    public DifficultySetting mediumDifficulty;
    public DifficultySetting largeDifficulty;

    public static DifficultySetting payload;
    public static bool hasPayload = false;

    public string gameScene = "GameScene";

    // Start is called before the first frame update
    void Start()
    {
        activeModal.alpha = 1.0f;
    }

    // Update is called once per frame
    void Update()
    {
        foreach (CanvasGroup group in canvasGroups)
        {
            if (group == activeModal){
                group.alpha = Mathf.MoveTowards(group.alpha,1,Time.unscaledDeltaTime * animSpeed);
                group.blocksRaycasts = true;
                group.interactable = true;
            }
            else{
                group.alpha = Mathf.MoveTowards(group.alpha,0,Time.unscaledDeltaTime * animSpeed);
                group.blocksRaycasts = false;
                group.interactable = false;
            }
        }
    }

    public void SetNextLevelDifficulty(int level){
        switch (level){
            case 1:
            payload = smallDifficulty;
            break;
            case 2:
            payload = mediumDifficulty;
            break;
            case 3:
            payload = largeDifficulty;
            break;
        }
        hasPayload = true;
        StartTransitToGameScene();
    }

    public void StartTransitToGameScene(){
        Debug.Log("Transiting to game scene");
        SceneManager.LoadScene(gameScene);
    }

    public void TransitToModal(CanvasGroup modal)
    {
        if (canvasGroups.Contains(modal))
        {
            activeModal = modal;
        }
    }

    public void Quit()
    {
        Application.Quit();
    }
}
