@if (Title != null)
{
    <MudText Typo="@TitleTypo">@Title</MudText>
}

<MudToggleGroup T="Student"
                SelectionMode="SelectionMode.ToggleSelection"
                Value="@SelectedCaptain"
                ValueChanged="@OnSelectedCaptainChanged"
                CheckMark>
    @foreach (var student in Students.OrderBy(e => e.FirstName))
    {
        <MudToggleItem Value="@student" Text="@student.Name" />
    }
</MudToggleGroup>

@code {
    [Parameter]
    public IEnumerable<Student> Students { get; set; } = [];

    [Parameter]
    public Student? SelectedCaptain { get; set; }

    [Parameter]
    public EventCallback<Student?> SelectedCaptainChanged { get; set; }

    [Parameter]
    public string? Title { get; set; } = "Captain";

    [Parameter]
    public Typo TitleTypo { get; set; } = Typo.body1;

    private async Task OnSelectedCaptainChanged(Student? value)
    {
        SelectedCaptain = value;
        await SelectedCaptainChanged.InvokeAsync(value);
    }
}
