using UnityEngine;
using UnityEngine.SceneManagement;

/// <summary>
/// ListMinigameScreen scene manager
/// </summary>
public class MinigameListManager : MonoBehaviour
{
    /// <summary>
    /// Reference to minigame-list container object
    /// </summary>
    public Transform minigameContainer;

    /// <summary>
    /// Prefab of the minigame item object
    /// </summary>
    public GameObject minigameItemPrefab;

    /// <summary>
    /// Reference to the list of all minigames
    /// </summary>
    public MinigameList minigameList;

    /// <summary>
    /// Start is called before the first frame update
    /// </summary>
    void Start()
    {
        foreach (Minigame minigame in minigameList.minigames)
        {
            // Create instance of prefab
            GameObject instance = GameObject.Instantiate(minigameItemPrefab, minigameContainer);

            // Dynamically load appearance
            MinigameItem item = instance.GetComponent<MinigameItem>();
            item.minigame = minigame;
        }
    }

    /// <summary>
    /// Method used as callback for minigame item onClick events
    /// </summary>
    /// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
    public void LoadScene(string sceneName)
    {
        SceneManager.LoadScene(sceneName);
    }
}
