<nav aria-label="Page navigation example">
    <ul class="pagination justify-content-center">
        @foreach (var link in links)
        {
            <li @onclick="@(() => SelectedPageInternal(link))"
                style="cursor: pointer;"
                class="page-item @(link.Enabled ? null : "disabled") @(link.Active ? "active" : null)">
                <span class="page-link" href="#">@((MarkupString)link.Text)</span>
            </li>
        }
    </ul>
</nav>

@code {
    private List<LinkModel> links;

    [Parameter]
    public int CurrentPage { get; set; }

    [Parameter]
    public int TotaPagesQuantity { get; set; }

    [Parameter]
    public int Radius { get; set; }

    [Parameter]
    public EventCallback<int> SelectedPage { get; set; }

    protected override void OnParametersSet()
    {
        this.LoadPages();
    }

    private async Task SelectedPageInternal(LinkModel link)
    {
        if (link.Page == this.CurrentPage)
        {
            return;
        }

        if (!link.Enabled)
        {
            return;
        }

        this.CurrentPage = link.Page;
        await this.SelectedPage.InvokeAsync(link.Page);
    }

    private void LoadPages()
    {
        this.links = new List<LinkModel>();
        var isPreviousPageLinkEnabled = this.CurrentPage != 1;
        var previousPage = this.CurrentPage - 1;
        this.links.Add(new LinkModel(previousPage, isPreviousPageLinkEnabled, "<i class=\"fas fa-chevron-left\"></i>"));

        for (int i = 1; i <= TotaPagesQuantity; i++)
        {
            if (i >= this.CurrentPage - this.Radius && i <= this.CurrentPage + this.Radius)
            {
                this.links.Add(new LinkModel(i) { Active = this.CurrentPage == i });
            }
        }

        var isNextPageLinkEnabled = this.CurrentPage != this.TotaPagesQuantity;
        var nextPage = this.CurrentPage + 1;
        this.links.Add(new LinkModel(nextPage, isNextPageLinkEnabled, "<i class=\"fas fa-chevron-right\"></i>"));
    }

    private class LinkModel
    {
        public LinkModel(int page)
            : this(page, true)
        {
        }

        public LinkModel(int page, bool enabled)
            : this(page, enabled, page.ToString())
        {
        }

        public LinkModel(int page, bool enabled, string text)
        {
            this.Page = page;
            this.Enabled = enabled;
            this.Text = text;
        }

        public string Text { get; set; }

        public int Page { get; set; }

        public bool Enabled { get; set; } = true;

        public bool Active { get; set; } = false;
    }
}