{% extends "cards.html" %}

      {% block header %}
      {% if consist.tags.all %}
      <p><small>Tags:</small>
        {% for t in consist.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
        {{ t.name }}</a>{# new line is required #}
        {% endfor %}
      </p>
      {% endif %}
      {% if not consist.published %}
      <span class="badge text-bg-warning">Unpublished</span> |
      {% endif %}
      <small class="text-body-secondary">Updated {{ consist.updated_time | date:"M d, Y H:i" }}</small>
      {% endblock %}
      {% block carousel %}
      {% if consist.image %}
      <div class="row pb-4">
        <div id="carouselControls" class="carousel carousel-dark slide" data-bs-ride="carousel">
          <div class="carousel-inner">
            <div class="carousel-item active">
              <img src="{{ consist.image.url }}" class="d-block w-100 rounded img-thumbnail" alt="Consist cover">
            </div>
          </div>
        </div>
      </div>
      {% endif %}
      {% endblock %}
      {% block cards_layout %}
      <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
      {% block cards %}
        {% for d in data %}
        {% include "cards/roster.html" %}
        {% endfor %}
      {% endblock %}
      </div>
      {% if loads %}
      <div class="accordion shadow-sm mt-4" id="accordionLoads">
        <div class="accordion-item">
          <h2 class="accordion-header">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseLoads" aria-expanded="false" aria-controls="collapseLoads">
              <i class="bi bi-download"></i>&nbsp;Rolling Stock loaded on freight cars
            </button>
          </h2>
          <div id="collapseLoads" class="accordion-collapse collapse" data-bs-parent="#accordionLoads">
            <div class="accordion-body">
              <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
                {% for l in loads %}
                {% include "cards/roster.html" with d=l %}
                {% endfor %}
              </div>
            </div>
          </div>
        </div>
      </div>
      {% endif %}
      {% endblock %}
      {% block pagination %}
      {% if data.has_other_pages %}
      <nav aria-label="Page navigation">
        <ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
          {% if data.has_previous %}
          <li class="page-item">
            <a class="page-link" href="{% url 'consist' uuid=consist.uuid page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
          </li>
          {% else %}
          <li class="page-item disabled">
            <span class="page-link"><i class="bi bi-chevron-left"></i></span>
          </li>
          {% endif %}
          {% for i in page_range %}
            {% if data.number == i %}
            <li class="page-item active">
              <span class="page-link">{{ i }}</span>
            </li>
            {% else %}
              {% if i == data.paginator.ELLIPSIS %}
              <li class="page-item"><span class="page-link">{{ i }}</span></li>
              {% else %}
              <li class="page-item"><a class="page-link" href="{% url 'consist' uuid=consist.uuid page=i %}#main-content">{{ i }}</a></li>
              {% endif %}
            {% endif %}
          {% endfor %}
          {% if data.has_next %}
          <li class="page-item">
            <a class="page-link" href="{% url 'consist' uuid=consist.uuid page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
          </li>
          {% else %}
          <li class="page-item disabled">
            <span class="page-link"><i class="bi bi-chevron-right"></i></span>
          </li>
          {% endif %}
        </ul>
      </nav>
      {% endif %}
      {% endblock %}
      {% block extra_content %}
      <section class="py-4 text-start container">
        <div class="row">
          <div class="mx-auto">
            <nav class="nav nav-tabs d-none d-lg-flex flex-row mb-2" id="nav-tab" role="tablist">
              <button class="nav-link active" id="nav-summary-tab" data-bs-toggle="tab" data-bs-target="#nav-summary" type="button" role="tab" aria-controls="nav-summary" aria-selected="true">Summary</button>
            </nav>
            <select class="form-select d-lg-none mb-2" id="tabSelector" aria-label="Tab selector">
              <option value="#nav-summary" selected>Summary</option>
            </select>
            <div class="tab-content" id="nav-tabContent">
              <div class="tab-pane show active table-responsive" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
                <table class="table table-striped">
                  <thead>
                    <tr>
                      <th colspan="2" scope="row">
                        Consist
                        <div class="float-end">
                          {% if consist.company.freelance %}
                          <span class="badge text-bg-secondary">Freelance</span>
                          {% endif %}
                        </div>
                      </th>
                    </tr>
                  </thead>
                  <tbody class="table-group-divider">
                    <tr>
                      <th class="w-33" scope="row">Company</th>
                      <td>
                        <a href="{% url 'filtered' _filter="company" search=consist.company.slug %}">{{ consist.company }}</a> ({{ consist.company.extended_name }})
                      </td>
                    </tr>
                    <tr>
                      <th scope="row">Era</th>
                      <td>{{ consist.era }}</td>
                    </tr>
                    {% if consist.description %}
                    <tr>
                      <th scope="row">Description</th>
                      <td>{{ consist.description | safe }}</td>
                    </tr>
                    {% endif %}
                    <tr>
                      <th scope="row">Length</th>
                      <td>{{ consist.length }}</td>
                    </tr>
                    <tr>
                      <th scope="row">Composition</th>
                      <td>{% for t in consist.get_type_count %}{{ t.count }}x {{ t.type }} {{t.category }}{% if not forloop.last %} &raquo; {% endif %}{% endfor %}{% if loads %} | <i class="bi bi-download"></i> {{ loads_count }}x Load{{ loads|pluralize }}{% endif %}</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
            <div class="d-grid gap-2 d-md-flex justify-content-md-end">
              {% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:consist_consist_change' consist.pk %}">Edit</a>{% endif %}
            </div>
          </div>
        </div>
      </section>
      {% endblock %}
