{% extends "base_list.html" %}
{% load mathfilters %}
{% load static %}
{% load naturalduration %}

{% block title %}{{object.title}}{% endblock %}

{% block head_extra %}
<style>
    .cover img {
        width: 250px;
    }

    .cover {
        float: left;
        width: 252px;
        padding: 0;
    }

    .summary {
        float: left;
        width: 600px;
        margin-left: 10px;
    }
</style>
{% endblock %}

{% block lists %}

<div class="row">
    {% if object.cover %}
    <div class="cover"><img src="{{object.cover.url}}" /></div>
    {% endif %}
    <div class="summary">
        {% if object.description%}
        <p>{{object.description|safe|linebreaks|truncatewords:160}}</p>
        <hr />
        {% endif %}
        <p style="float:right;">
            <a href="{{object.bggeek_link}}"><img src="{% static "images/bgg-logo.png" %}" width=35></a>
        </p>
    </div>
</div>
<div class="row">
    <p>{{scrobbles.count}} scrobbles</p>
    <p>
        <a href="{{object.start_url}}">Play again</a>
    </p>
    {% if object.genre.all %}
    <p>Genres:
        {% for tag in object.genre.all %}
        <a href="{% url 'boardgames:boardgame_list' %}?genre={{ tag.name|urlencode }}" class="badge bg-secondary text-decoration-none">{{ tag.name }}</a>
        {% endfor %}
    </p>
    {% endif %}
    {% if object.tags.all %}
    <p>Tags:
        {% for tag in object.tags.all %}
        <a href="{% url 'boardgames:boardgame_list' %}?tag={{ tag.name|urlencode }}" class="badge bg-secondary text-decoration-none">{{ tag.name }}</a>
        {% endfor %}
    </p>
    {% endif %}
</div>
{% if charts %}
<div class="row">
    <div class="col-md">
        {% include "scrobbles/_chart_links.html" %}
    </div>
</div>
{% endif %}
<div class="row">
    <div class="col-md">
        <h3>Last scrobbles</h3>
        <div class="table-responsive">
            <table class="table table-striped table-sm">
                <thead>
                    <tr>
                        <th scope="col">Date</th>
                        <th scope="col">Location</th>
                        <th scope="col">Players</th>
                    </tr>
                </thead>
                <tbody>
                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                    <tr>
                        <td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
                        <td>{{scrobble.logdata.location }}</td>
                        <td>{% if scrobble.logdata.player_log %}{{scrobble.logdata.as_html|safe }}{% else %}No data{% endif %}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    {% if is_paginated %}
    <div class="pagination">
        {% if page_obj.has_previous %}
        <a href="?page={{ page_obj.previous_page_number }}">&laquo; Previous</a>
        {% endif %}

        {% for num in page_obj.paginator.page_range %}
        {% if num == page_obj.number %}
            <strong>{{ num }}</strong>
        {% else %}
            <a href="?page={{ num }}">{{ num }}</a>
        {% endif %}
        {% endfor %}

        {% if page_obj.has_next %}
        <a href="?page={{ page_obj.next_page_number }}">Next &raquo;</a>
        {% endif %}
    </div>
    {% endif %}
</div>
{% endblock %}
