using UnityEngine;
using System.Collections.Generic;

public class ThemeManager : MonoBehaviour
{
    public static ThemeManager Instance { get; private set; }

    public List<VisualTheme> themes;
    private VisualTheme currentTheme;

    private const string SelectedThemeKey = "SelectedThemeIndex";

    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }
        Instance = this;
        DontDestroyOnLoad(gameObject);

        LoadTheme();
    }

    private void LoadTheme()
    {
        int selectedThemeIndex = PlayerPrefs.GetInt(SelectedThemeKey, 0);
        if (themes != null && themes.Count > selectedThemeIndex)
        {
            currentTheme = themes[selectedThemeIndex];
            Debug.Log("Тема загружена: " + currentTheme.themeName);
        }
        else
        {
            Debug.LogError("Не удалось загрузить тему! Проверьте список тем в ThemeManager.");
        }
    }

    public void SetTheme(int themeIndex)
    {
        if (themes != null && themes.Count > themeIndex)
        {
            PlayerPrefs.SetInt(SelectedThemeKey, themeIndex);
            PlayerPrefs.Save();
            currentTheme = themes[themeIndex];
            Debug.Log("Тема выбрана: " + currentTheme.themeName);
        }
    }

    // Методы для получения ассетов текущей темы
    public VisualTheme GetCurrentTheme()
    {
        if (currentTheme == null)
        {
            LoadTheme();
        }
        return currentTheme;
    }
}
