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

public class CharacterListController : MonoBehaviour
{
    public GameObject togglePrefab;
    public StringSharedField playerAccountName;

    public Transform listParent;

    GameObject characterToggleGO;
    CharacterToggleInstance characterToggle;

    PlayerAccountData playerAccount;
    CharacterData characterData;

    private void Awake()
    {
        playerAccount = PlayerDataHandler.Instance.LoadPlayerAccountData(playerAccountName.Value);
    }

    private void Start()
    {
        GenerateCharacterListFromAccountData(playerAccount);
    }


    private void GenerateCharacterListFromAccountData(PlayerAccountData accountData)
    {
        foreach (string characterName in accountData.characterNames)
        {
            characterData = PlayerDataHandler.Instance.LoadCharacterData(playerAccountName.Value, characterName);

            characterToggleGO = Instantiate(togglePrefab, listParent);
            characterToggle = characterToggleGO.GetComponent<CharacterToggleInstance>();

            characterToggle.InitializeCharacterToggle(characterData);
        }
    }
}
