@inject IJSRuntime JSRuntime
@inject ILocalizationService LocalizationService
@inject NavigationManager Navigation

@* <select @bind="_selectedCulture" @onchange="OnCultureChanged">
    <option value="en-US">English</option>
    <option value="zh-CN">中文</option>
    <option value="ja-JP">日本語</option>
</select> *@

@code {
    private string _selectedCulture = "en-US";

    protected override async Task OnInitializedAsync()
    {
        _selectedCulture = await JSRuntime.InvokeAsync<string>("blazorCulture.get") ?? "en-US";
    }

    private async Task OnCultureChanged(ChangeEventArgs e)
    {
        var culture = e.Value?.ToString();
        if (!string.IsNullOrEmpty(culture))
        {
            await JSRuntime.InvokeVoidAsync("blazorCulture.set", culture);
            await LocalizationService.LoadResourcesAsync(culture);
            Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
        }
    }
}