using BlazorApp1.Components;
using BlazorApp1.Models;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;

namespace BlazorApp1.Pages
{
    public partial class Inventory
    {
        [Inject]
        public IDataService DataService { get; set; }

        private int totalItem;
        public List<Item> Items { get; set; } = new List<Item>();

        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            base.OnAfterRenderAsync(firstRender);

            if (!firstRender)
            {
                return;
            }

            Items = await DataService.List(0, await DataService.Count());

            StateHasChanged();
        }
        private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
        {
            if (e.CancellationToken.IsCancellationRequested)
            {
                return;
            }

            if (!e.CancellationToken.IsCancellationRequested)
            {
                Items = await DataService.List(e.Page, e.PageSize);
                totalItem = await DataService.Count();
            }
        }
    }
}
