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

<MudToggleGroup T="Student"
                SelectionMode="SelectionMode.MultiSelection"
                Values="@SelectedStudents"
                ValuesChanged="@OnSelectedStudentsChanged"
                Vertical="true"
                CheckMark>
    @foreach (var student in Students.OrderBy(e => e.FirstName))
    {
        <MudToggleItem Value="@student" Style="font-size: .75rem;">
            @if (ShowFullName)
            {
                @student.FirstNameLastName
            }
            else
            {
                @student.FirstName
            }
        </MudToggleItem>
    }
</MudToggleGroup>

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

    [Parameter]
    public IEnumerable<Student> SelectedStudents { get; set; } = [];

    [Parameter]
    public EventCallback<IEnumerable<Student>> SelectedStudentsChanged { get; set; }

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

    [Parameter]
    public bool ShowFullName { get; set; } = true;

    private async Task OnSelectedStudentsChanged(IEnumerable<Student> value)
    {
        SelectedStudents = value;
        await SelectedStudentsChanged.InvokeAsync(value);
    }
}
