@page "/Box/BoxAddBox"

<style>
    @@keyframes shake {
        0% {
            opacity: 1;
            color: red;
        }

        25% {
            opacity: 1;
            color: orange;
        }

        50% {
            opacity: 0;
            color: yellow;
        }

        75% {
            opacity: 1;
            color: crimson;
        }

        100% {
            opacity: 1;
            color: red;
        }
    }

    .rz-custom-header {
        width: 100%;
    }

    .shaky-text {
        animation: shake 2s infinite ease-in-out;
        /* 你可以根据需要调整动画的持续时间和迭代次数 */
        transition: color 0.5s linear,opacity 0.5s linear;
    }

</style>

<div class="container-fluid">

    <RadzenDataGrid @ref="grid" RowSelect="@OnRowSelect" TItem="ChannelList"
                    RowRender="@RowRender"
                    EmptyText="无数据"
                    Data="@_forecasts" @bind-Value=@selectedChannelLists
                    AllowColumnResize="true" AllowAlternatingRows="false"
                    SelectionMode="DataGridSelectionMode.Single" LoadData="@LoadData" IsLoading="@isLoading" 
                    Count="@count" AllowPaging="true" PageSize="10" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true" PagingSummaryFormat="{0}/{1} 共{2}条数据"
                    ExpandMode="DataGridExpandMode.Multiple">
        <Template Context="cs">
            <RadzenDataGrid Data="@cs.ChannelStocks" EmptyText="无数据">
                <Columns>
                    <RadzenDataGridColumn Title="药品名称" Property="Drug.DrugName">
                    </RadzenDataGridColumn>
                    <RadzenDataGridColumn Title="规格" Property="Drug.DrugSpec">
                    </RadzenDataGridColumn>
                    <RadzenDataGridColumn Title="厂家" Property="Drug.Manufactory">
                    </RadzenDataGridColumn>
                    @*  <RadzenDataGridColumn Title="批次" Property="ManuNo"></RadzenDataGridColumn>
                    <RadzenDataGridColumn Title="效期" Property="EffDate">
                    </RadzenDataGridColumn> *@
                    <RadzenDataGridColumn Title="基数" Property="BaseQuantity">
                    </RadzenDataGridColumn>
                    <RadzenDataGridColumn Title="需补药数" Property="NeedQuantity">
                    </RadzenDataGridColumn>
                </Columns>
            </RadzenDataGrid>
        </Template>
        <Columns>
            <RadzenDataGridColumn Frozen="true" Width="200px" Title="药盒号" Property="DrawerNo">
                <Template Context="DrawerNo">
                    @DrawerNo.DrawerNo 号药盒
                </Template>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn Title="总库存" Property="TotalQuantity"></RadzenDataGridColumn>
        </Columns>
    </RadzenDataGrid>
</div>

@code {
    @inject IChannelListDao channelStockDao;
    @inject DialogService dialogService;
    RadzenDataGrid<ChannelList> grid;
    bool isLoading;
    int count;
    private IEnumerable<ChannelList>? _forecasts;
    DateTime start;
    DateTime end;

    IList<ChannelList> selectedChannelLists;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
       
    }
    async Task LoadData(LoadDataArgs args)
    {
        isLoading = true;

        var result = await channelStockDao.GetBoxWaitInfo(args.Top, args.Skip);
        // Update the Data property
        _forecasts = result.Desserts;
        isLoading = false;
    }

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

        if (firstRender)
        {
            // await grid.ExpandRows(grid.PagedView.Where(di => di.Stocks.Count > 0));
        }
    }
    void RowRender(RowRenderEventArgs<ChannelList> args)
    {
        args.Expandable = args.Data.ChannelStocks.Count > 0;
    }

    async void OnRowSelect(ChannelList cl)
    {
        var b = await dialogService.OpenAsync<BoxAddBoxDetailDialog>(
               $"{cl.DrawerNo}号药盒药品入库",
             new Dictionary<string, object>() { { "boxChannelList", cl } },
             new DialogOptions() { Width = "85vw", Resizable = true, Draggable = true, ShowClose = false }
       );
        if (b)
        {
            await grid.Reload();
        }
    }


    async void StockExport()
    {

    }

    async void AccountBookExport()
    {

    }



}