using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;

public class RaceModText : MonoBehaviour
{
    TMP_Text _text;

    void Awake()
    {
        _text = GetComponent<TMP_Text>();
        SpeciesAndClassCounter.Changed += UpdateRaceModText;
    }

    void UpdateRaceModText()
    {
        StringBuilder b = new StringBuilder();
        var classes = SpeciesAndClassCounter.BattlersByClass.OrderByDescending(t => t.Value.Count);
        foreach (var entry in classes)
        {
            int count = SpeciesAndClassCounter.BattlersByClass[entry.Key].Count;
            string aspect = entry.Key.DisplayName;
            var color = entry.Key.DisplayColor;
            b.AppendLine($"<color=#{color.ToHexString()}> {aspect} {count}</color>");
        }
        
        var species = SpeciesAndClassCounter.BattlersBySpecies.OrderByDescending(t => t.Value.Count);
        foreach (var entry in species)
        {
            int count = SpeciesAndClassCounter.BattlersBySpecies[entry.Key].Count;
            string aspect = entry.Key.DisplayName;
            var color = entry.Key.DisplayColor;
            b.AppendLine($"<color=#{color.ToHexString()}> {aspect} {count}</color>");
        }
        
        
        _text.SetText(b);
    }
}
