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 string CurrentThemeName { get; private set; } = "Fluent"; public static readonly List AvailableThemes = ["Fluent", "BlazingBerry", "Purple", "OfficeWhite", "BootstrapExternal"]; public event Action? OnChange; public void SetTheme(string themeName) { if (CurrentThemeName == themeName) return; CurrentThemeName = themeName; ApplyTheme(); OnChange?.Invoke(); } public void SetDarkMode(bool isDarkMode) { if (IsDarkMode == isDarkMode) return; IsDarkMode = isDarkMode; ApplyTheme(); OnChange?.Invoke(); } private void ApplyTheme() { if (CurrentThemeName == "Fluent") { var theme = Themes.Fluent.Clone(properties => { properties.Mode = IsDarkMode ? ThemeMode.Dark : ThemeMode.Light; properties.ApplyToPageElements = true; }); themeChangeService.SetTheme(theme); } else if (CurrentThemeName == "BlazingBerry") themeChangeService.SetTheme(Themes.BlazingBerry); else if (CurrentThemeName == "Purple") themeChangeService.SetTheme(Themes.Purple); else if (CurrentThemeName == "OfficeWhite") themeChangeService.SetTheme(Themes.OfficeWhite); else if (CurrentThemeName == "BootstrapExternal") themeChangeService.SetTheme(Themes.BootstrapExternal); else themeChangeService.SetTheme(Themes.Fluent); OnChange?.Invoke(); } }