@using LEA.Models
@inject UserManager<ApplicationUser> UserManager
@{
    ApplicationUser? currentUser = null;
    if (User.Identity?.IsAuthenticated ?? false)
    {
        currentUser = await UserManager.GetUserAsync(User);
    }

    var displayName = currentUser?.FullName;
}
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>@ViewData["Title"] - LEA Bewerbungs-Tracker</title>
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
    <link rel="stylesheet" href="~/LEA.styles.css" asp-append-version="true" />
</head>
<body>
    <header class="site-header">
        <nav class="main-nav">
            <a class="brand" asp-controller="Home" asp-action="Index">LEA Bewerbungs-Tracker</a>
            <button class="nav-toggle" type="button" aria-label="Navigation umschalten" data-target="primary-nav">
                <span></span>
                <span></span>
                <span></span>
            </button>
            <div class="nav-menu" id="primary-nav">
                <ul class="nav-links">
                    <li><a asp-controller="Home" asp-action="Index" class="@(ViewContext.RouteData.Values["controller"]?.ToString() == "Home" ? "active" : null)">Start</a></li>
                    @if (User.Identity?.IsAuthenticated ?? false)
                    {
                        <li><a asp-controller="Applications" asp-action="Index" class="@(ViewContext.RouteData.Values["controller"]?.ToString() == "Applications" ? "active" : null)">Bewerbungen</a></li>
                    }
                    <li><a asp-controller="Home" asp-action="Privacy">Datenschutz</a></li>
                </ul>
                <div class="nav-actions">
                    @if (User.Identity?.IsAuthenticated ?? false)
                    {
                        <span class="nav-user">Hallo, @(string.IsNullOrWhiteSpace(displayName) ? User.Identity?.Name : displayName)</span>
                        <form asp-controller="Account" asp-action="Logout" method="post">
                            @Html.AntiForgeryToken()
                            <button type="submit" class="btn btn-outline">Abmelden</button>
                        </form>
                    }
                    else
                    {
                        <a class="btn btn-link" asp-controller="Account" asp-action="Login">Anmelden</a>
                        <a class="btn btn-primary" asp-controller="Account" asp-action="Register">Registrieren</a>
                    }
                </div>
            </div>
        </nav>
    </header>

    <div class="flash-container">
        @if (TempData["Success"] is string successMessage)
        {
            <div class="flash-message success" role="status">
                <span>@successMessage</span>
                <button type="button" class="flash-close" aria-label="Meldung schließen">&times;</button>
            </div>
        }
        @if (TempData["Error"] is string errorMessage)
        {
            <div class="flash-message error" role="status">
                <span>@errorMessage</span>
                <button type="button" class="flash-close" aria-label="Meldung schließen">&times;</button>
            </div>
        }
    </div>

    <main class="site-main">
        @RenderBody()
    </main>

    <footer class="site-footer">
        <div class="footer-inner">
            <p>&copy; @DateTime.Now.Year LEA Bewerbungs-Tracker</p>
            <div class="footer-links">
                <a asp-controller="Home" asp-action="Index">Start</a>
                <a asp-controller="Home" asp-action="Privacy">Datenschutz</a>
            </div>
        </div>
    </footer>

    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js" crossorigin="anonymous"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>
