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

public class CourseScreenManager : MonoBehaviour
{
    [Header("Course Screen Components")]
    // Reference to text that displays when there are no recent courses
    public GameObject noRecentCourses;
    // Reference to recent-courses-list holder object
    public Transform recentCourses;
    // Reference to recommended-courses-list holder object
    public Transform recommendedCourses;

    [Header("Prefabs")]
    // CourseItem prefab
    public GameObject course_item;

    // TODO: change to ScriptableObject;
    [Header("ScriptableObjects")]
    public int numberOfRecentCourses;
    public string[] recentCourseTitle;
    public float[] recentCourseProgress;
    public Sprite[] recentCourseThumbnail;
    public string[] recentCourseScene;
    public int numberOfRecommendedCourses;
    public string[] recommendedCourseTitle;
    public float[] recommendedCourseProgress;
    public Sprite[] recommendedCourseThumbnail;
    public string[] recommendedCourseScene;

    void Start()
    {
        // Recent courses
        noRecentCourses.SetActive(numberOfRecentCourses <= 0);

        for (int i = 0; i < numberOfRecentCourses; i++)
        {
            // Create instance of prefab
            GameObject instance = GameObject.Instantiate(course_item, recentCourses);

            // Dynamically load appearance
            CourseItem item = instance.GetComponent<CourseItem>();
            item.courseTitle = recentCourseTitle[i];
            item.courseThumbnail = recentCourseThumbnail[i];
            item.courseProgress = recentCourseProgress[i];
            item.courseScene = recentCourseScene[i];
        }

        // Recommended courses
        for (int i = 0; i < numberOfRecommendedCourses; i++)
        {
            // Create instance of prefab
            GameObject instance = GameObject.Instantiate(course_item, recommendedCourses);

            // Dynamically load appearance
            CourseItem item = instance.GetComponent<CourseItem>();
            item.courseTitle = recommendedCourseTitle[i];
            item.courseThumbnail = recommendedCourseThumbnail[i];
            item.courseProgress = 0.0f; // So progress bar doesn't show
            item.courseScene = recommendedCourseScene[i];
        }
    }

    // Method used as callback for on click events
    public void LoadScene(string sceneName)
    {
        SceneManager.LoadScene(sceneName);
    }
}
