@implements IDisposable

@if (Model.ErrorCount > 0)
{
    <div class="folder-error">
        @ErrorStr
    </div>
}
@if (Model.WarningCount > 0)
{
    <div class="folder-warnning">
        @WarningStr
    </div>
}

@code {

    [Parameter, EditorRequired]
    public IHierachyItemModel Model { get; set; } = default!;

    private string ErrorStr => Model.ErrorCount < 10 ? Model.ErrorCount.ToString() : "9+";

    private string WarningStr => Model.WarningCount < 10 ? Model.WarningCount.ToString() : "9+";

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
        if (firstRender)
        {
            Model.OnDiagnosticsChanged += OnDiagnosticsChanged;
        }
    }

    private void OnDiagnosticsChanged(int warningCount, int errorCount)
    {
        StateHasChanged();
    }

    public void Dispose()
    {
        Model.OnDiagnosticsChanged -= OnDiagnosticsChanged;
        GC.SuppressFinalize(this);
    }
}
