using UnityEngine;
using UnityEngine.SceneManagement;

/// <summary>
/// ListCourseScreen scene manager
/// </summary>
public class CourseListManager : MonoBehaviour
{
    /// <summary>
    /// Reference to the course-list container object
    /// </summary>
    public Transform courseContainer;

    /// <summary>
    /// Prefab of the course item object
    /// </summary>
    public GameObject courseItemPrefab;

    /// <summary>
    /// Reference to the list of all courses
    /// </summary>
    public CourseList courseList;

    /// <summary>
    /// Start is called before the first frame update
    /// </summary>
    void Start()
    {
        foreach (Course course in courseList.courses)
        {
            // Create instance of prefab
            GameObject instance = GameObject.Instantiate(courseItemPrefab, courseContainer);

            // Dynamically load appearance
            CourseItem item = instance.GetComponent<CourseItem>();
            item.course = course;
        }
    }

    /// <summary>
    /// Method used as callback for course 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);
    }
}
