{% extends "base.html" %}
{% block content %}
<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">
        {{ entry.movie().title().value() }}
        <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">
        <span class="star {% if entry.review().rating().value() >= 1 %}filled{% else %}empty{% endif %}">★</span>
        <span class="star {% if entry.review().rating().value() >= 2 %}filled{% else %}empty{% endif %}">★</span>
        <span class="star {% if entry.review().rating().value() >= 3 %}filled{% else %}empty{% endif %}">★</span>
        <span class="star {% if entry.review().rating().value() >= 4 %}filled{% else %}empty{% endif %}">★</span>
        <span class="star {% if entry.review().rating().value() >= 5 %}filled{% else %}empty{% endif %}">★</span>
      </div>
      {% if let Some(comment) = entry.review().comment() %}
      <div class="comment">{{ comment.value() }}</div>
      {% endif %}
      <div class="watched-at">{{ entry.review().watched_at().format("%Y-%m-%d") }}</div>
      {% if let Some(uid) = ctx.user_id %}
        {% if *uid == entry.review().user_id().value() %}
        <form method="post" action="/reviews/{{ entry.review().id().value() }}/delete" class="delete-form">
          <input type="hidden" name="_csrf" value="{{ ctx.csrf_token }}">
          <button type="submit">Delete</button>
        </form>
        {% endif %}
      {% endif %}
    </div>
  </article>
  {% else %}
  <p class="empty">No movies logged yet.</p>
  {% endfor %}
</div>
<nav class="pagination">
  {% if current_offset > 0 %}
  <a href="/?offset={{ current_offset - limit }}" 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 }}" class="page-num">{{ item.number + 1 }}</a>
  {% endif %}
  {% endfor %}
  {% if has_more %}
  <a href="/?offset={{ current_offset + limit }}" class="page-nav">Next &rarr;</a>
  {% endif %}
</nav>
{% endblock %}
