{% extends "base_list.html" %}
{% load urlreplace %}

{% block title %}Webpages{% endblock %}

{% block lists %}
{% if domains_this_week or domains_this_month %}
<div class="row">
    <div class="col-md">
        <h2>Domains Read</h2>

        <div class="pagination" style="margin-bottom:10px;">
            <span class="page-links">
                {% if domain_page > 1 %}
                    <a href="?{% urlreplace domain_page=domain_page|add:'-1' %}">prev</a>
                {% endif %}
                    <span class="page-current">
                        Page {{ domain_page }} of {{ domain_paginator.num_pages }}
                    </span>
                {% if domain_page < domain_paginator.num_pages %}
                    <a href="?{% urlreplace domain_page=domain_page|add:'1' %}">next</a>
                {% endif %}
            </span>
        </div>

        {% if domains_this_week %}
        <h3>This Week</h3>
        <div class="table-responsive">
            <table class="table table-striped table-sm">
                <tbody>
                    {% for item in domains_this_week %}
                    <tr>
                        <td>{{item.domain}}</td>
                        <td>{{item.count}} pages</td>
                    </tr>
                    {% empty %}
                    <tr><td>No pages read this week</td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% endif %}

        {% if domains_this_month %}
        <h3>This Month</h3>
        <div class="table-responsive">
            <table class="table table-striped table-sm">
                <tbody>
                    {% for item in domains_this_month %}
                    <tr>
                        <td>{{item.domain}}</td>
                        <td>{{item.count}} pages</td>
                    </tr>
                    {% empty %}
                    <tr><td>No pages read this month</td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% endif %}

    </div>
</div>
{% endif %}

<div class="row">
    <p class="pagination">
        <span class="page-links">
            {% if page_obj.has_previous %}
                <a href="?{% urlreplace page=page_obj.previous_page_number %}">prev</a>
            {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
                </span>
            {% if page_obj.has_next %}
                <a href="?{% urlreplace page=page_obj.next_page_number %}">next</a>
            {% endif %}
        </span>
    </p>
    <hr />

    {% if view == 'grid' %}
    <div>
        {% for webpage in object_list %}
        {% if webpage.thumbnail %}
        <dl style="width: 130px; float: left; margin-right:10px;">
            <dd><img src="{{webpage.primary_image_url}}" width=120 height=120 /></dd>
        </dl>
        {% endif %}
        {% endfor %}
    </div>
    {% else %}
    <div class="col-md">
        <div class="table-responsive">
            <table class="table table-striped table-sm">
            <thead>
                <tr>
                    <th scope="col">Scrobbles</th>
                    <th scope="col">Webpage</th>
                </tr>
            </thead>
            <tbody>
                {% for webpage in object_list %}
                <tr>
                    <td>{{webpage.scrobble_count}}</td>
                    <td><a href="{{webpage.get_absolute_url}}">{{webpage}}</a></td>
                </tr>
                {% endfor %}
            </tbody>
            </table>
        </div>
    </div>
    {% endif %}

    <div class="pagination" style="margin-bottom:50px;">
        <span class="page-links">
            {% if page_obj.has_previous %}
                <a href="?{% urlreplace page=page_obj.previous_page_number %}">prev</a>
            {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
                </span>
            {% if page_obj.has_next %}
                <a href="?{% urlreplace page=page_obj.next_page_number %}">next</a>
            {% endif %}
        </span>
    </div>
</div>
{% endblock %}
