@*
    EN: App root — hosts the single set of MudBlazor providers (FRONT-W-06).
        Theme and dark mode are controlled via ThemeStateService; layouts call SetTheme on init.
    VI: Root ứng dụng — host bộ MudBlazor providers duy nhất (FRONT-W-06).
        Theme và dark mode được điều khiển qua ThemeStateService; layout gọi SetTheme khi khởi tạo.
*@
@using WebClientTpos.Client.Services
@inject ThemeStateService ThemeState
@implements IDisposable

<MudThemeProvider IsDarkMode="@ThemeState.IsDarkMode" Theme="@ThemeState.CurrentTheme" />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />

<Router AppAssembly="@typeof(App).Assembly" NotFoundPage="typeof(Pages.NotFound)">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
</Router>

@code {
    protected override void OnInitialized()
    {
        ThemeState.OnChange += StateHasChanged;
    }

    public void Dispose()
    {
        ThemeState.OnChange -= StateHasChanged;
    }
}
