@rendermode InteractiveServer
@attribute [Authorize]

@using Microsoft.AspNetCore.Authorization
@using WorkManagementTool.Services
@inject HomeworkService HomeworkService

<button class="btn btn-primary" @onclick="ToggleHomeworkStatus">Toogle done/undone</button>

@code {
    [Parameter]
    public int IdHomework { get; set; }

    [Parameter]
    public EventCallback<int> OnToogle { get; set; }

    private bool? Worked { get; set; } = null;

    public async Task ToggleHomeworkStatus(MouseEventArgs e)
    {
        Worked = await HomeworkService.ToggleHomeworkStatusAsync(IdHomework);
        if (Worked.HasValue && Worked.Value)
            await OnToogle.InvokeAsync(IdHomework);
    }
}
