{% extends 'base.html' %}{% load static %}

{% block headtitle %}Media{% if source %} - {{ source }}{% endif %}{% endblock %}

{% block content %}
<div class="row">
  <div class="col s12 m6">
    <h1 class="truncate">Media</h1>
  </div>
  <div class="col s12 m3">
    {% if show_skipped %}
    <a href="{% url 'sync:media' %}{% if source %}?filter={{ source.pk }}{% endif %}" class="btn"><i class="far fa-eye-slash"></i> Hide skipped media</a>
    {% else %}
    <a href="{% url 'sync:media' %}?show_skipped=yes{% if source %}&filter={{ source.pk }}{% endif %}" class="btn"><i class="far fa-eye"></i> Show skipped media</a>
    {% endif %}
  </div>
  <div class="col s12 m3">
    {% if only_skipped %}
    <a href="{% url 'sync:media' %}{% if source %}?filter={{ source.pk }}{% endif %}" class="btn"><i class="far fa-eye-slash"></i> Only skipped media</a>
    {% else %}
    <a href="{% url 'sync:media' %}?only_skipped=yes{% if source %}&filter={{ source.pk }}{% endif %}" class="btn"><i class="far fa-eye"></i> Only skipped media</a>
    {% endif %}
  </div>
</div>
{% include 'infobox.html' with message=message %}
<div class="row no-margin-bottom">
  {% for m in media %}
  <div class="col s12 m6 l4 xl3">
    <div class="card mediacard">
      <a href="{% url 'sync:media-item' pk=m.pk %}" title="{{ m.source.name }} / {{ m.name }}">
        <div class="card-image">
          <img src="{% if m.thumb %}{% url 'sync:media-thumb' pk=m.pk %}{% else %}{% static 'images/nothumb.png' %}{% endif %}">
          <span class="card-title truncate">{{ m.source }}<br>
            <span>{{ m.name }}</span><br>
            <span>
            {% if m.downloaded %}
              <i class="fas fa-check-circle" title="Downloaded"></i> {{ m.download_date|date:'Y-m-d' }}
            {% else %}
              {% if m.skip %}
              <span class="error-text"><i class="fas fa-times" title="Skipping media"></i> Skipped</span>
              {% elif not m.source.download_media %}
              <span class="error-text"><i class="fas fa-times" title="Not downloading media for this source"></i> Disabled at source</span>
              {% elif not m.has_metadata %}
              <i class="far fa-clock" title="Waiting for metadata"></i> Fetching metadata
              {% elif m.can_download %}
              <i class="far fa-clock" title="Waiting to download or downloading"></i> Downloading
              {% else %}
              <span class="error-text"><i class="fas fa-exclamation-triangle" title="No matching formats to download"></i> No matching formats</span>
              {% endif %}
            {% endif %}
            </span>
          </span>
        </div>
      </a>
    </div>
  </div>
  {% empty %}
  <div class="col s12">
    <div class="collection">
      <span class="collection-item no-items"><i class="fas fa-info-circle"></i> No media has been indexed{% if source %} that matches the specified source filter{% endif %}.</span>
    </div>
  </div>
  {% endfor %}
</div>
{% include 'pagination.html' with pagination=sources.paginator filter=source.pk show_skipped=show_skipped %}
{% endblock %}
