using AntDesign;
using AntDesign.TableModels;
using EasyTemplate.Tool;
using Microsoft.JSInterop;

namespace EasyTemplate.Blazor.Web.Components.Pages.Management.Area;

public partial class Area
{
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await NavigationManager.RedirectLogin(IJSRuntime);
        }
    }

    /// <summary>
    /// 查
    /// </summary>
    /// <returns></returns>
    private async Task Query()
    {
        Loading = true;
        DataSource = await Repository.AsQueryable().OrderBy(x => x.Sort).ToTreeAsync(x => x.Children, x => x.ParentCode, 0, x => x.AreaCode);
        Loading = false;
    }

    private async Task OnChange(QueryModel<SystemArea> query)
    => await Query();

    /// <summary>
    /// 账号
    /// </summary>
    private string Q_Name { get; set; }
    /// <summary>
    /// 注入实例
    /// </summary>
    [Inject] SqlSugarRepository<SystemArea> Repository { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [Inject] NavigationManager NavigationManager { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [Inject] IJSRuntime IJSRuntime { get; set; }
    /// <summary>
    ///
    /// </summary>
    private ITable Table;
    /// <summary>
    ///
    /// </summary>
    private IEnumerable<SystemArea> SelectedRows = [];
    /// <summary>
    ///
    /// </summary>
    private List<SystemArea> DataSource;
    /// <summary>
    ///
    /// </summary>
    private int Pi = 1;
    /// <summary>
    ///
    /// </summary>
    private int Ps = 20;
    /// <summary>
    ///
    /// </summary>
    private int _total;
    /// <summary>
    ///
    /// </summary>
    private bool Loading = false;

    private async Task CheckDuplication()
    {
        var list = await Repository.AsQueryable().ToListAsync();
        var dup = list.GroupBy(x => x.AreaCode).Where(g => g.Count() > 1).ToList();
    }
}


