@page "/add/invoice"
@code {
    @inject IInOutInvoiceDao inOutInvoiceDao;
    @inject DialogService dialogService;
    @inject Toolbelt.Blazor.I18nText.I18nText I18nText;
    private I18nText.local myText = new I18nText.local();
    RadzenDataGrid grid;
    bool isLoading;
    int count;
    private IEnumerable? _forecasts;
    string InvoiceNo;
    DateTime InvoiceDate = DateTime.MinValue;
    protected override async Task OnInitializedAsync()
    {
        myText = await I18nText.GetTextTableAsync(this);
        base.OnInitializedAsync();
    }
    void OnCurrentDateChanged(DateTime args)
    {
        InvoiceDate = new DateTime(args.Year, args.Month, args.Day);
    }
    async Task LoadData(LoadDataArgs args)
    {
        isLoading = true;
        var result = await inOutInvoiceDao.GetAllInvoiceByType(InvoiceNo, InvoiceDate, args.Top, args.Skip, 1);
        // Update the Data property
        _forecasts = result.Desserts;
        // Update the count
        count = result.TotalDesserts;
        isLoading = false;
    }
    async Task reloadGrid()
    {
        InvoiceNo = "";
        InvoiceDate = DateTime.MinValue;
        await grid.Reload();
    }
    async Task InvoiceSelected(InOutInvoice oi)
    {
        var b = await dialogService.OpenAsync(
                myText.InvoiceInDetail,
              new Dictionary() { { "invoice", oi } },
              new DialogOptions() { Width = "85vw", Resizable = true, Draggable = true, ShowClose = false }
        );
        if (b)
        {
            await reloadGrid();
        }
    }
    
}