{% extends "layouts/base.html" %}
{% load indexing %}
{% block title %} Events {% endblock %} 

<!-- Specific Page CSS goes HERE  -->
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}

  <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center py-4">
      <div class="d-block mb-4 mb-md-0">
          <nav aria-label="breadcrumb" class="d-none d-md-inline-block">
              <ol class="breadcrumb breadcrumb-dark breadcrumb-transparent">
                  <li class="breadcrumb-item">
                      <a href="/">
                          <svg class="icon icon-xxs" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path></svg>
                      </a>
                  </li>
                  <li class="breadcrumb-item"><a href="{% url 'dashboard' %}">BRACE2</a></li>
                  <li class="breadcrumb-item">Events</li>
                  <li class="breadcrumb-item active" aria-current="page">CGS</li>
              </ol>
          </nav>
          <h2 class="h4">All Events</h2>

      </div>
      <div class="btn-toolbar mb-2 mb-md-0">
        {% if false %}
          <a href="#" class="btn btn-sm btn-gray-800 d-inline-flex align-items-center">
              <svg class="icon icon-xs me-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path></svg>
              New Event
          </a>
        {% endif %}
        <span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" title="Disabled" data-bs-placement="left">
          <div class="btn-group ms-2 ms-lg-3" disabled>
              <button type="button" class="btn btn-sm btn-outline-gray-600" onClick="print()" style="pointer-events: none;">Print</button>
              <button type="button" class="btn btn-sm btn-outline-gray-600" style="pointer-events: none;">Export</button>
          </div>
        </span>
      </div>
  </div>
  
  <div class="table-settings mb-4">
      <div class="row align-items-center justify-content-between">
          <div class="col col-md-6 col-lg-3 col-xl-4">
            <span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-placement="right" title="Disabled">
              <div class="input-group me-2 me-lg-3 fmxw-400">
                  <span class="input-group-text">
                      <svg class="icon icon-xs" x-description="Heroicon name: solid/search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                          <path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd"></path>
                      </svg>
                  </span>
                  <input disabled type="text" class="form-control" placeholder="Search events">
              </div>
            </span>
          </div>
          {% if false %}
          {# TODO: Implement drop-down pagination #}
          <div class="col-4 col-md-2 col-xl-1 ps-md-0 text-end">
              <div class="dropdown">
                  <button class="btn btn-link text-dark dropdown-toggle dropdown-toggle-split m-0 p-1" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                      <svg class="icon icon-sm" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z" clip-rule="evenodd"></path></svg>
                      <span class="visually-hidden">Toggle Dropdown</span>
                  </button>
                  <div class="dropdown-menu dropdown-menu-xs dropdown-menu-end pb-0">
                      <span class="small ps-3 fw-bold text-dark">Show</span>
                      <a class="dropdown-item d-flex align-items-center fw-bold" href="#">10 <svg class="icon icon-xxs ms-auto" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"></path></svg></a>
                      <a class="dropdown-item fw-bold" href="#">20</a>
                      <a class="dropdown-item fw-bold rounded-bottom" href="#">30</a>
                  </div>
              </div>
          </div>
          {% endif %}
      </div>
  </div>
  
  <div class="card card-body border-0 shadow table-wrapper table-responsive">
      <table class="table table-hover">
      <thead>
      <tr>
          <th>CALID</th>
          {# <th>CESMD</th> #}
          <th>Station name</th>
          <th>Date</th>
      </tr>
      </thead>
      <tbody>
      {% for event in events %}
          <tr style="cursor: pointer;" 
              {% if False %}
            onClick="window.location='/evaluations/{{ event.id }}/{{ event.cesmd }}/';">
              {% endif %}
              onClick="window.location='{% url 'asset_event_summary' event=event.id cesmd=event.cesmd %}';">
          <td>
            <code>{{ event.asset.calid }}</code>
          </td>
          {% with station_name_list=event.motion_data.station_name.split %}
            {# TODO: Clean up procedure #}
            {% if "interchange" in station_name_list|last|lower %}
              <td>{{ event.motion_data.station_name|slice:"2:"|title }}</td>
            {% else %}
              <td>{{ station_name_list|slice:"1:-1"|join:" "|title }}</td>
            {% endif %}
          {% endwith %}
          <td>{{ event.motion_data.event_date }}</a></td>
          </tr>
      {% endfor %}
      </tbody>
      </table>

  <div class="card-footer px-3 border-0 d-flex flex-column flex-lg-row align-items-center justify-content-between">
      <nav aria-label="Page navigation example">
          <ul class="pagination mb-0">
            <li class="page-item {% if not events.has_previous %}disabled{% endif %}">
                {% if events.has_previous %}
                  <a class="page-link" href="?page={{ events.previous_page_number }}/">Previous</a>
                {% else %}
                  <a class="page-link disabled" href="#">Previous</a>
                {% endif %}
              </li>
              {% for page in events.paginator.page_range %}
              {% if page <= events.number|add:3 and page >= events.number|add:-3 %}
              <li class="page-item {% if page == events.number %}active{% endif %}">
                  <a class="page-link" href="?page={{ page }}">{{ page }}</a>
              </li>
              {% endif %}
              {% endfor %}
              <li class="page-item {% if not events.has_next %}disabled{% endif %}">
                {% if events.has_next %}
                    <a class="page-link" href="?page={{ events.next_page_number }}/">Next</a>
                {% else %}
                  <a class="page-link disabled" href="#">Next</a>
                {% endif %}
              </li>
          </ul>
      </nav>
      <div class="fw-normal small mt-4 mt-lg-0">Showing <b>{{ events|length }}</b> out of <b>{{ events.paginator.count }}</b> entries</div>
  </div>
</div>

{% endblock content %}

<!-- Specific Page JS goes HERE  -->

{% block javascripts %}
<script>
    const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
    const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
</script>
{% endblock javascripts %}
