{% extends "base.html" %}
{% block content %}
<form method="get" class="feed-filters" action="/">
  {% if ctx.user_email.is_some() %}
  <label class="pill{% if filter == "all" %} active{% endif %}">
    <input type="radio" name="filter" value="all"
           {% if filter == "all" %}checked{% endif %}
           onchange="this.form.submit()">
    Global
  </label>
  <label class="pill{% if filter == "following" %} active{% endif %}">
    <input type="radio" name="filter" value="following"
           {% if filter == "following" %}checked{% endif %}
           onchange="this.form.submit()">
    Following
  </label>
  {% endif %}
  {% include "_filter_controls.html" %}
  {% if filter != "all" || sort_by != "date" || !search.is_empty() %}
  <a href="/" class="clear-filters">Clear</a>
  {% endif %}
  <input type="hidden" name="limit" value="{{ limit }}">
</form>
<div class="diary">
  {% for entry in entries %}
  <article class="entry">
    {% if let Some(poster) = entry.movie().poster_path() %}
    <div class="poster">
      <img src="{{ poster.value()|poster_src }}" alt="">
    </div>
    {% endif %}
    <div class="entry-body">
      <div class="entry-title">
        <a href="/movies/{{ entry.movie().id().value() }}" class="movie-title-link">{{ entry.movie().title().value() }}</a>
        <span class="year">({{ entry.movie().release_year().value() }})</span>
      </div>
      {% if let Some(dir) = entry.movie().director() %}
      <div class="director">{{ dir }}</div>
      {% endif %}
      <div class="rating">
        {% for filled in entry.review().stars() %}
          <span class="star {% if filled %}filled{% else %}empty{% endif %}">★</span>
        {% endfor %}
      </div>
      {% if let Some(wm) = entry.review().watch_medium() %}
      <span class="watch-medium">{{ wm.label() }}</span>
      {% endif %}
      {% if let Some(comment) = entry.review().comment() %}
      <div class="comment">{{ comment.value() }}</div>
      {% endif %}
      <div class="feed-meta">
        {% match entry.review().source() %}
        {% when ReviewSource::Remote with { actor_url } %}
        <a href="{{ actor_url }}" class="feed-user" target="_blank" rel="noopener noreferrer">{{ entry.user_display_name() }}</a>
        <span class="feed-time">{{ entry.review().watched_at().format("%b %-d, %Y") }}</span>
        <span class="remote-badge">&#8599; federated</span>
        {% when ReviewSource::Local %}
        <a href="/users/{{ entry.review().user_id().value() }}" class="feed-user">{{ entry.user_display_name() }}</a>
        <span class="feed-time">{{ entry.review().watched_at().format("%b %-d, %Y") }}</span>
        {% endmatch %}
      </div>
      {% if ctx.is_current_user(entry.review().user_id().value()) %}
      <form method="post" action="/reviews/{{ entry.review().id().value() }}/delete" class="delete-form">
        <input type="hidden" name="redirect_after" value="/?offset={{ current_offset }}{{ self.filter_qs() }}">
        <input type="hidden" name="_csrf" value="{{ ctx.csrf_token }}">
        <button type="submit">Delete</button>
      </form>
      {% endif %}
    </div>
  </article>
  {% else %}
  <p class="empty">No movies logged yet.</p>
  {% endfor %}
</div>
<nav class="pagination">
  {% if current_offset >= limit %}
  <a href="/?offset={{ current_offset - limit }}{{ self.filter_qs() }}" class="page-nav">&larr; Prev</a>
  {% endif %}
  {% for item in page_items %}
  {% if item.is_ellipsis %}
  <span class="page-ellipsis">&hellip;</span>
  {% elif item.is_current %}
  <span class="page-num current">{{ item.number + 1 }}</span>
  {% else %}
  <a href="/?offset={{ item.number * limit }}{{ self.filter_qs() }}" class="page-num">{{ item.number + 1 }}</a>
  {% endif %}
  {% endfor %}
  {% if has_more %}
  <a href="/?offset={{ current_offset + limit }}{{ self.filter_qs() }}" class="page-nav">Next &rarr;</a>
  {% endif %}
</nav>
{% endblock %}
