@inherits LayoutComponentBase
@inject NavigationManager Navigation
@inject UserContext UserContext

<div class="app-shell">
    <header class="brand-header">
        <span class="brand-white">AS</span><span class="brand-red">TRAIN</span>
    </header>
    <main class="main-content">
        @Body
    </main>

    <nav class="bottom-nav">
        <a class="nav-item" href="@GetLink("routines")">Routines</a>

        <div class="nav-logo">
            <img src="logo_square.png" alt="ASTRAIN" />
        </div>

<a class="nav-item" href="@GetLink("exercises")">Exercises</a>


    </nav>
</div>

@code {
    private string GetLink(string page)
    {
        var uri = new Uri(Navigation.Uri);
        var segments = uri.AbsolutePath.Trim('/').Split('/', StringSplitOptions.RemoveEmptyEntries);
        var userId = segments.Length > 0 && segments[0].Length == 8 ? segments[0] : UserContext.UserId;

        return string.IsNullOrWhiteSpace(userId) ? $"/{page}" : $"/{userId}/{page}";
    }
}
