﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Arugula.Games;

namespace Arugula.UI
{
    public class ScoreboardList : MonoBehaviour
    {
        public string id;
        public GameObject template;

        List<GameObject> instances = new List<GameObject>();

        private void OnEnable()
        {
            var sb = Scoreboard.Get(id);

            if (sb == null)
                return;


            for (int i = 0; i < sb.Archived.Count; i++)
            {
                var go = Instantiate(template, transform);
                instances.Add(go);
                var field = go.GetComponent<ScoreboardEntryField>();
                field.Apply(sb, i);
            }

        }

        private void OnDisable()
        {
            foreach (var go in instances)
                Destroy(go);

            instances.Clear();
        }
    }

}
