@using Shared.DTOs
@inject HttpClient _hc
@inject NavigationManager Navigation

<div class="tp-faq-area pt-50" id="Question">
    <div class="container p-0">
        <div class="row g-0">
            <div class="col-xl-12">
              
                <div class="popular-blog-title mb-40">
                    <h4>سوالات پر تکرار</h4>
                </div>
                <div class="tp-custom-accordion">
                    <div class="accordion" id="accordionExample">
                        @for (int i = 0; i < request?.list.Count; i++)
                        {
                         
                            <ItemQuestion qitem="request?.list[i]" />
                        }
                        @*
                        @foreach (var item in request?.list)
                        {
                        <ItemQuestion Item="item" />
                        } *@

                    </div>
                </div>
            </div>
        </div>
       
    </div>
    <br />
    @if (request!=null)
    {
        <div class="container">

            <Pagination TotalPages=@request.PageCount
                        ActivePageNumber="@PageIndex"
                        PageChanged="OnPageChangedAsync"
                        Alignment="Alignment.Center"
                        FirstLinkIcon="IconName.ChevronDoubleRight"
                        PreviousLinkIcon="IconName.ChevronRight"

                        NextLinkIcon="IconName.ChevronLeft"
                        LastLinkIcon="IconName. ChevronDoubleLeft" />


        </div>
    }
    
</div>

@code {
    [Parameter]
    public int PageIndex { get; set; }


    public Shared.DTOs.PagingDto<QuestionDto>? request { get; set; }
    private async Task OnPageChangedAsync(int newPageNumber)
    {
        request = await _hc.GetFromJsonAsync<PagingDto<QuestionDto>>($"Base/LastQuestion?PageIndex={newPageNumber}&PageSize=5");

        await Task.Run(() => { PageIndex = newPageNumber; });
    }
    protected override async Task OnParametersSetAsync()
    {
        request = await _hc.GetFromJsonAsync<PagingDto<QuestionDto>>($"Base/LastQuestion?PageIndex={PageIndex}&PageSize=5");
        await base.OnParametersSetAsync();
    }
}
