{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

<nav class="pagination is-centered" aria-label="pagination">
  {{#if this.hasPrevious}}
    <LinkTo @route={{this.link}} @models={{this.models}} @query={{hash page=(dec this.page)}} class="pagination-previous">
      <Chevron @direction="left" />
      <span class="pagination-previous-label">
        Previous
      </span>
    </LinkTo>
  {{else}}
    <button type="button" disabled={{true}} class="pagination-previous is-invisible" aria-hidden={{true}}>
      <Chevron @direction="left" />
      <span class="pagination-previous-label">
        Previous
      </span>
    </button>
  {{/if}}
  {{#if this.hasNext}}
    <LinkTo @route={{this.link}} @models={{this.models}} @query={{hash page=(inc this.page)}} class="pagination-next">
      <span class="pagination-next-label">
        Next
      </span>
      <Chevron />
    </LinkTo>
  {{else}}
    <button type="button" disabled={{true}} class="pagination-next is-invisible" aria-hidden={{true}}>
      <span class="pagination-next-label">
        Next
      </span>
      <Chevron />
    </button>
  {{/if}}
  {{#if this.segmentLinks}}
    <ul class="pagination-list">
      <li>
        <LinkTo
          @route={{this.link}}
          @models={{this.models}}
          @query={{hash page=1}}
          class={{concat (if (eq this.page 1) "is-current ") "pagination-link"}}
          aria-label="Go to page 1"
        >
          1
        </LinkTo>
      </li>
      <li><span class="pagination-ellipsis">&hellip;</span></li>
      {{#each this.pageRange as |p|}}
        <li>
          <LinkTo
            @route={{this.link}}
            @models={{this.models}}
            @query={{hash page=p}}
            class={{concat (if (eq this.page 1) "is-current ") "pagination-link"}}
            aria-label={{concat "Go to page " p}}
          >
            {{p}}
          </LinkTo>
        </li>
      {{/each}}
      <li><span class="pagination-ellipsis">&hellip;</span></li>
      <li>
        <LinkTo
          @route={{this.link}}
          @models={{this.models}}
          @query={{hash page=this.lastPage}}
          class={{concat (if (eq this.page this.lastPage) "is-current ") "pagination-link"}}
          aria-label={{concat "Go to page " this.lastPage}}
        >
          {{this.lastPage}}
        </LinkTo>
      </li>
    </ul>
  {{else}}
    <ul class="pagination-list">
      {{#each this.pageRange as |p|}}
        <li>
          <LinkTo
            @route={{this.link}}
            @models={{this.models}}
            @query={{hash page=p}}
            class={{concat (if (eq this.page p) "is-current ") "pagination-link"}}
            aria-label={{concat "Go to page " p}}
          >
            {{p}}
          </LinkTo>
        </li>
      {{/each}}
    </ul>
  {{/if}}
</nav>