@page "/students/details"
@using Microsoft.EntityFrameworkCore
@using Core.Entities
@using Data
@inject AppDbContext context
@inject NavigationManager NavigationManager

<PageTitle>Student Details - TSA Chapter Organizer</PageTitle>

<h1>Details</h1>

<div>
    <h2>Student</h2>
    <hr />
    @if (student is null)
    {
        <p><em>Loading...</em></p>
    }
    else {
        <dl class="row">
            <dt class="col-sm-2">FirstName</dt>
            <dd class="col-sm-10">@student.FirstName</dd>
            <dt class="col-sm-2">LastName</dt>
            <dd class="col-sm-10">@student.LastName</dd>
            <dt class="col-sm-2">Grade</dt>
            <dd class="col-sm-10">@student.Grade</dd>
            <dt class="col-sm-2">Email</dt>
            <dd class="col-sm-10">@student.Email</dd>
            <dt class="col-sm-2">PhoneNumber</dt>
            <dd class="col-sm-10">@student.PhoneNumber</dd>
            <dt class="col-sm-2">TsaYear</dt>
            <dd class="col-sm-10">@student.TsaYear</dd>
            <dt class="col-sm-2">StateId</dt>
            <dd class="col-sm-10">@student.StateId</dd>
            <dt class="col-sm-2">RegionalId</dt>
            <dd class="col-sm-10">@student.RegionalId</dd>
            <dt class="col-sm-2">NationalId</dt>
            <dd class="col-sm-10">@student.NationalId</dd>
            <dt class="col-sm-2">OfficerRole</dt>
            <dd class="col-sm-10">@student.OfficerRole</dd>
        </dl>
        <div>
            <a href="@($"/students/edit?id={student.Id}")">Edit</a> |
            <a href="@($"/students")">Back to List</a>
        </div>
    }
</div>

@code {
    private Student? student;

    [SupplyParameterFromQuery]
    private int Id { get; set; }

    protected override async Task OnInitializedAsync()
    {
        student = await context.Students.FirstOrDefaultAsync(m => m.Id == Id);

        if (student is null)
        {
            NavigationManager.NavigateTo("notfound");
        }
    }
}
