<h2 class="my-3">{{ page_title }}</h2>
<article>
  <a href="{{ "admin/page/new/edit" | relative_link }}" class="btn btn-primary btn-sm mb-3">Create a New Page</a>
  {%- assign page_count = pages | size -%}
  <table class="table table-sm table-hover">
    <thead>
      <tr>
        <th scope="col">Title</th>
        <th scope="col">Permalink</th>
        <th scope="col">Last Updated</th>
      </tr>
    </thead>
    <tbody>
      {% if page_count > 0 %}
        {% for pg in pages -%}
          <tr>
            <td>
              {{ pg.title }}
              {%- if pg.is_default %} &nbsp; <span class="badge bg-success">HOME PAGE</span>{% endif -%}
              {%- if pg.show_in_page_list %} &nbsp; <span class="badge bg-primary">IN PAGE LIST</span> {% endif -%}<br>
              <small>
                {%- capture pg_link %}{% unless pg.is_default %}{{ pg.permalink }}{% endunless %}{% endcapture -%}
                <a href="{{ pg_link | relative_link }}" target="_blank">View Page</a>
                <span class="text-muted"> &bull; </span>
                <a href="{{ pg | edit_page_link }}">Edit</a>
                <span class="text-muted"> &bull; </span>
                {%- capture pg_del %}admin/page/{{ pg.id }}/delete{% endcapture -%}
                {%- capture pg_del_link %}{{ pg_del | relative_link }}{% endcapture -%}
                <a href="{{ pg_del_link }}" class="text-danger"
                   onclick="return Admin.deletePage('{{ pg.title }}', '{{ pg_del_link }}')">
                  Delete
                </a>
              </small>
            </td>
            <td>/{% unless pg.is_default %}{{ pg.permalink }}{% endunless %}</td>
            <td>{{ pg.updated_on | date: "MMMM d, yyyy" }}</td>
          </tr>
        {%- endfor %}
      {% else %}
        <tr>
          <td colspan="3" class="text-muted fst-italic text-center">This web log has no pages</td>
        </tr>
      {% endif %}
    </tbody>
  </table>
  {% if page_nbr > 1 or page_count == 25 %}
    <div class="d-flex justify-content-evenly">
      <div>
        {% if page_nbr > 1 %}
          {%- capture prev_link %}admin/pages{{ prev_page }}{% endcapture -%}
          <p><a class="btn btn-default" href="{{ prev_link | relative_link }}">&laquo; Previous</a></p>
        {% endif %}
      </div>
      <div class="text-right">
        {% if page_count == 25 %}
          {%- capture next_link %}admin/pages{{ next_page }}{% endcapture -%}
          <p><a class="btn btn-default" href="{{ next_link | relative_link }}">Next &raquo;</a></p>
        {% endif %}
      </div>
    </div>
  {% endif %}
  <form method="post" id="deleteForm">
    <input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
  </form>
</article>
