@page "/blog"
@page "/blog/posts"
@page "/blog/categories"
@attribute [Authorize(Roles = "Administrator")]

<div>
    <MudText Typo="Typo.h5" Class="mb-3">مدیریت بلاگ</MudText>

    <MudTabs Elevation="0" Rounded="true" Border="true" ApplyEffectsToContainer="true"
             PanelClass="pt-4" @bind-ActivePanelIndex="_activeTab">
        <MudTabPanel Text="پست‌ها" Icon="@Icons.Material.Filled.PostAdd">
            <BlogPostManagementPage />
        </MudTabPanel>
        <MudTabPanel Text="دسته‌بندی‌ها" Icon="@Icons.Material.Filled.Category">
            <BlogCategoryManagementPage />
        </MudTabPanel>
    </MudTabs>
</div>

@code {
    private int _activeTab;

    protected override void OnInitialized()
    {
        var uri = Navigation.ToBaseRelativePath(Navigation.Uri).ToLowerInvariant().TrimEnd('/');
        _activeTab = uri switch
        {
            "blog/categories" => 1,
            _ => 0
        };
    }
}
