{% macro render_series_timeline(series) %}
  {% for day, grouped_series in series|groupby_attrs('added_on_date') %}
      <h2 class="text-regular text-uppercase font-weight-black mb-3">{{day|to_date|timeline_date}}</h2>
      <div class="carousel">
          <div class="carousel__items py-2">
              {% for s in grouped_series %}
                  <div class="carousel-item">
                      {% set episode_hash = 'e' ~ s.episode.id %}
                      <div class="card-episode">
                          <a href="{{ url_for('main.series_detail', series_id=s.id, view='list', _anchor=episode_hash) }}">
                              <img class="card-episode__image w-100 img-fluid rounded" loading="lazy" src="{{ s.episode.thumbnail }}" width="300" height="170"
                              alt="Still for episode {{s.episode.season_episode_id}}" />
                          </a>           
                          <a href="{{ url_for('main.series_detail', series_id=s.id) }}">
                              <img class="card-episode__poster img-fluid rounded" loading="lazy" src="{{ s.poster }}" width="340" height="500" alt="Poster for {{ s.name }}" />                                            
                          </a>
                      </div>
                      <div>
                          <h2 class="text-sm text-muted text-uppercase mb-2">{{s.episode.season_episode_id}}</h2>
                          <h3 class="text-regular mb-1">
                              <a class="" href="{{ url_for('main.series_detail', series_id=s.id, view='list', _anchor=episode_hash) }}">
                                  {{ s.episode.name }} 
                              </a>
                          </h3>                        
                          <p class="text-muted text-sm">{{ "{:,}".format(s.release_count)}} new torrents</p>                        
                      </div>
                  </div>
              {% endfor %}
          </div>
      </div>
      {% if not loop.last %}
          <hr class="my-5">
      {% endif %}
  {% endfor %}
{% endmacro %}

{% macro render_series_card(series) %}
    <div class="card-series">        
        <a href="{{ url_for( 'main.series_detail', series_id=series.id) }}">
            <img class="card-series__image rounded img-fluid" src="{{ series.poster }}" width="500" height="750"
                loading="lazy" alt="Poster for {{series.name}}" />
            <h3 class="card-series__name my-1 font-weight-normal text-sm text-center">{{series.name}}</h3>
        </a>
    </div>
{% endmacro %}

{% macro air_date(value, today) %}
    {% if value %}
        {% if value <= today %}
            {{value | human_date}}
        {% else %}
            Will air {{value | human_date}}
        {% endif %} 
    {% else %}
        &nbsp;
    {% endif %}
{% endmacro %}