using DevExpress.Blazor;

namespace DbFirst.BlazorWebApp.Services;

public class ThemeState
{
    private readonly IThemeChangeService themeChangeService;

    public ThemeState(IThemeChangeService themeChangeService)
    {
        this.themeChangeService = themeChangeService;
    }

    public bool IsDarkMode { get; private set; }

    public event Action? OnChange;

    public void SetDarkMode(bool isDarkMode)
    {
        if (IsDarkMode == isDarkMode)
        {
            return;
        }

        IsDarkMode = isDarkMode;
        var theme = Themes.Fluent.Clone(properties =>
        {
            properties.Mode = isDarkMode ? ThemeMode.Dark : ThemeMode.Light;
            properties.ApplyToPageElements = true;
        });

        themeChangeService.SetTheme(theme);
        OnChange?.Invoke();
    }
}
