using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class CharacterToggleInstance : MonoBehaviour
{
    public StringSharedField selectedCharacterName;
    public StringSharedField selectedCharacterClass;
    public Toggle toggle;
    public TMP_Text characterName;
    public TMP_Text characterLevel;
    public List<GameObject> classIcon;

    public CharacterData character;

    ToggleGroup toggleGroup;

    private void Awake()
    {
        toggleGroup = GetComponentInParent<ToggleGroup>();

        toggle.group = toggleGroup;
    }

    public void InitializeCharacterToggle(CharacterData characterData)
    {
        character = characterData;
        characterName.text = characterData.characterName;
        characterLevel.text = characterData.currentLevel.ToString();
        UpdateClassIcon(characterData.characterClass);
    }

    public void UpdateClassIcon(string characterClass)
    {
        for (int i = 0; i < classIcon.Count; i++)
        {
            if (characterClass.Contains(classIcon[i].name))
            {
                classIcon[i].SetActive(true);
            }
            else
            {
                classIcon[i].SetActive(false);
            }
        }
    }

    public void OnValueChanged(bool value)
    {
        if (value)
        {
            selectedCharacterClass.Value = character.characterClass;
            selectedCharacterName.Value = character.characterName;
            Debug.Log("UpdatedSelected character to: " + selectedCharacterName.Value + " " + selectedCharacterClass.Value);
        }
    }
}
