using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

namespace Nan.Scripts
{
    public class ScoreRanking : MonoBehaviour
    {
        private void Start()
        {
            var i = 0; 
            var stringBuilder = new StringBuilder();
            foreach (var rank in ScoreManager.Instance.Ranking.OrderBy(v => -v))
            {
                stringBuilder.AppendLine(AddOrdinal(i + 1) + ": " + rank);
                ++i;
            }
            GetComponent<Text>().text = stringBuilder.ToString();
        }

        public static string AddOrdinal(int num)
        {
            if (num <= 0) return num.ToString();

            if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13)
                return num + "th";

            switch (num % 10)
            {
                case 1:
                    return num + "st";
                case 2:
                    return num + "nd";
                case 3:
                    return num + "rd";
                default:
                    return num + "th";
            }

        }
    }
}