@inject IKeyService keyService

@inject IJSRuntime jsRuntime;


<div tabindex="0"
     style="margin: auto;"
     @onkeydown="HandleKeyDown"
     @onkeyup="HandleKeyUp"
     @onkeydown:preventDefault="true"
     @onkeydown:stopPropagation="true">
    @ChildContent
</div>

@code {

    [Parameter]
    public RenderFragment ChildContent { get; set; } = default!;

    private void HandleKeyDown(KeyboardEventArgs e)
    {
        keyService.AddPressedKey(e.Key);
    }

    private void HandleKeyUp(KeyboardEventArgs e)
    {
        keyService.RemovePressedKey(e.Key);
    }

    protected override bool ShouldRender()
    {
#if DEBUG
        jsRuntime.InvokeVoidAsync("console.time", "InputPanelComponent");
#endif

        return true;
    }

    protected override void OnAfterRender(bool firstRender)
    {
#if DEBUG
        jsRuntime.InvokeVoidAsync("console.timeEnd", "InputPanelComponent");
#endif
    }

}