using Microsoft.AspNetCore.Components.Web;
using Radzen;
using Radzen.Blazor;
using RadzenTest.Models;

namespace RadzenTest.Components.Pages
{
    public partial class RadzenDataGridReset
    {
        private RadzenDataGrid<User> _dataGrid;
        private bool _isLoading;
        private List<User> _users;

        private async Task loadUsers(LoadDataArgs arg)
        {
            // NOTE:
            // Issue: The LoadData callback delegate is infinitely called when _dataGrid.Reset(); is called when a SortOrder is defined on a column in the DataGrid.
            //  - This appears to be directly related to the change made to RadzenDataGridColumn.razor.cs in v10.0.0
            
            // And inconsistent behavior happens depending on if a SortOrder is defined or not on the columns of the DataGrid.
            //  - If a SortOrder is defined, then the LoadData callback delegate is automatically invoked
            //  - Buf if no SortOrder is defined, then the LoadData callback delegate is not automatically invoked and we must call Reload

            _isLoading = true;

            _users = await User.GetUsers();

            _isLoading = false;
        }

        private async Task ResetDataGrid(MouseEventArgs arg)
        {
            _dataGrid.Reset();
            //await _dataGrid.Reload();
        }

        private Task OnEdit(User context)
        {
            return Task.CompletedTask;
        }
    }
}
