@page "/settings" @attribute [Authorize] @inject IUserSessionService Session @inject IJSRuntime JS @inject TranslationSource T @rendermode InteractiveServer @using Microsoft.JSInterop

@T["tab.settings"]

@T["settings.section.display"]
@T["settings.section.behavior"]
@T["settings.section.branding"]

@T["settings.logo.description"]

@if (_saved) {
@T["settings.saved"]
} @code { private string _lang = "en", _theme = "System"; private bool _autoTakeOwnership, _saved; private LogoData? _mspLogo; protected override void OnInitialized() { var s = Session.Settings; // Reflect the culture actually resolved for this circuit (cookie-driven), not the // possibly-not-yet-loaded persisted setting. _lang = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "fr" ? "fr" : "en"; _theme = s.Theme is "System" or "Light" ? s.Theme : "System"; _autoTakeOwnership = s.AutoTakeOwnership; _mspLogo = s.MspLogo; } private async Task OnMspLogoChanged(LogoData? logo) { _mspLogo = logo; await Save(); } private async Task Save() { var langChanged = !string.Equals(Session.Settings.Lang, _lang, StringComparison.Ordinal); Session.UpdateSettings(new AppSettings { Lang = _lang, Theme = _theme, AutoTakeOwnership = _autoTakeOwnership, MspLogo = _mspLogo }); T.SetCulture(_lang); await JS.InvokeVoidAsync("sptb.setTheme", _theme); // Persisted above. A full reload restarts the circuit; MainLayout then applies the new // language (from the just-saved settings) before anything renders. if (langChanged) { await JS.InvokeVoidAsync("location.reload"); return; } _saved = true; StateHasChanged(); _ = Task.Delay(2000).ContinueWith(_ => { _saved = false; InvokeAsync(StateHasChanged); }); } }