@page "/system/area"
@attribute [ReuseTabsPage(Title = "区域管理")]

<Spin Spinning="Loading">
    <Table @ref="Table" AutoHeight TItem="SystemArea" DataSource="DataSource"
           @bind-PageSize="Ps" @bind-PageIndex="Pi" TreeChildren="item=>item.Children" @bind-SelectedRows="SelectedRows"
           OnChange="OnChange">
        <ColumnDefinitions Context="row">
            <PropertyColumn Align="ColumnAlign.Center" Property="c => c.AreaName" Title="区域名称" />
            <PropertyColumn Align="ColumnAlign.Center" Property="c => c.AreaCode" Title="区域编码" />
            <PropertyColumn Align="ColumnAlign.Center" Property="c => c.Level" Title="层级" />
        </ColumnDefinitions>
        <PaginationTemplate>
            <Pagination Class="@(context.PaginationClass + " my-custom-pagination")"
                        Total="context.Total"
                        PageSize="context.PageSize"
                        Current="context.PageIndex"
                        ShowSizeChanger
                        ShowQuickJumper
                        OnChange="context.HandlePageChange" />
        </PaginationTemplate>
    </Table>
</Spin>

@inject ModalService ModalService;
@inject ConfirmService ComfirmService;
@inject IMessageService _message;

@code {

    private async Task OnExpand(SystemArea row)
    {
        var data = row;
        if (data.Children == null)
        {
            await AddChildren(data);
        }
    }

    async Task AddChildren(SystemArea row)
    {
        await Task.Delay(1000);
        var index = row.Children?.Count() ?? 0;
        row.Children = row.Children ?? [];
    }

}
