@using GridCore.Pagination
@using GridCore.Resources
@using GridShared.Pagination;
@model GridPager
@if (Model == null || Model.PageCount <= 1)
{
    return;
}

@{
    string _changePageSizeUrl = (string) ViewData["changePageSizeUrl"];
    string _goToUrl = (string) ViewData["goToUrl"];
    PagingType _pagingType = (PagingType)ViewData["pagingType"];
    int _pageSize = Model.ChangePageSize && Model.QueryPageSize > 0 ? Model.QueryPageSize : Model.PageSize;
}

<div class="grid-pager-sizer">
    <nav class="grid-pager" data-currentpage="@Model.CurrentPage">
        <ul class="pagination">
            @if (Model.CurrentPage > 1)
            {
                <li class="page-item">
                    <a href="#" class="page-link grid-page-link" data-page="@(Model.CurrentPage - 1)">«</a>
                </li>
            }

            @if (Model.StartDisplayedPage > 1)
            {
                <li class="page-item">
                    <a href="#" class="page-link grid-page-link" data-page="1">1</a>
                </li>
                if (Model.StartDisplayedPage > 2)
                {
                    <li class="page-item"><a href="#" class="page-link grid-page-link" data-page="@(Model.StartDisplayedPage - 1)">...</a></li>
                }
            }
            @for (int i = Model.StartDisplayedPage; i <= Model.EndDisplayedPage; i++)
            {
                if (i == Model.CurrentPage)
                {
                    <li class="page-item active"><span class="page-link grid-page-link">@i</span></li>
                }
                else
                {
                    <li class="page-item"><a href="#" class="page-link grid-page-link" data-page="@i">@i</a></li>
                }
            }
            @if (Model.EndDisplayedPage < Model.PageCount)
            {
                if (Model.EndDisplayedPage < Model.PageCount - 1)
                {
                    <li class="page-item"><a href="#" class="page-link grid-page-link" data-page="@(Model.EndDisplayedPage + 1)">...</a></li>
                }
                <li><a href="#" class="page-link grid-page-link" data-page="@Model.PageCount">@Model.PageCount</a></li>
            }
            @if (Model.CurrentPage < Model.PageCount)
            {
                <li class="page-item"><a href="#" class="page-link grid-page-link" data-page="@(Model.CurrentPage + 1)">»</a></li>
            }
        </ul>
    </nav>

    @if (Model.GoToVisibility)
    {
        <div class="grid-goto-page form-group" data-goto-page-url="@_goToUrl">
            <label class="control-label"><b>@Strings.Goto</b></label>
            <div>
                <input class="form-control grid-goto-page-input" value="@Model.CurrentPage" />
            </div>
        </div>
    }

    @if (_pagingType == PagingType.Pagination && Model.ChangePageSize)
    {
        <div class="grid-change-page-size form-group" data-change-page-size-url="@_changePageSizeUrl">
            <label class="control-label"><b>@Strings.Show</b></label>
            <div>
                <input class="form-control grid-change-page-size-input" value="@_pageSize" />
            </div>
            <label class="control-label"><b>@Strings.Items</b></label>
        </div>
    }
</div>
