{% extends "admin/index.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}

{% load i18n static %}

{% block content %}
    <div id="content-main">
        <h2>Welcome to procrastination heaven !</h2>

        {% if app_list %}
            {% for app in app_list %}
                <div class="app-{{ app.app_label }} module">
                    <table>
                        <caption>
                            <a href="{{ app.app_url }}" class="section"
                               title="{% blocktrans with name=app.name %}Models in the {{ name }} application{% endblocktrans %}">{{ app.name }}</a>
                        </caption>
                        {% for model in app.models %}
                            <tr class="model-{{ model.object_name|lower }}">
                                {% if model.admin_url %}
                                    <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
                                {% else %}
                                    <th scope="row">{{ model.name }}</th>
                                {% endif %}

                                {% if model.add_url %}
                                    <td><a href="{{ model.add_url }}" class="addlink">{% trans 'Add' %}</a></td>
                                {% else %}
                                    <td>&nbsp;</td>
                                {% endif %}

                                {% if model.admin_url %}
                                    <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
                                {% else %}
                                    <td>&nbsp;</td>
                                {% endif %}
                            </tr>
                        {% endfor %}
                    </table>
                </div>
            {% endfor %}
        {% endif %}

        <img src="{% static "images/splash.png" %}" class="poulpy" alt="Poulpy">
    </div>
{% endblock %}


{% block sidebar %}
    <div id="content-related">
        <div class="module" id="recent-actions-module">
            {% if user.is_authenticated %}
                <h2>{{ user.first_name }} {{ user.last_name }}</h2>

                <h3>
                    {% trans 'My profile' %}
                    <small><a class="changelink" href="{% url 'users:edit-info' %}">
                        {% trans 'Edit' %}
                    </a></small>
                </h3>
                <ul>
                    <li><strong>{% trans 'username' %}</strong> : {{ user.username }}</li>
                    <li><strong>{% trans 'email' %}</strong> : {{ user.email }}</li>
                    <li><strong>{% trans 'comment' %}</strong> : {{ user.comment }}</li>
                    <li><strong>{% trans 'date joined' %}</strong> : {{ user.date_joined }}</li>
                    <li><strong>{% trans 'last login' %}</strong> : {{ user.last_login }}</li>
                    <li><strong>{% trans 'address' %}</strong> : {{ user.address }}</li>
                    <li><strong>{% trans 'phone number' %}</strong> : {{ user.telephone }}</li>
                    <li><strong>{% trans 'groups' %}</strong> : {% for g in user.groups.all %}{{ g.name }} {% endfor %}
                    </li>
                    <li><strong>{% trans 'maximum borrowed' %}</strong> : {{ user.maxemprunt }}</li>
                    <li>
                        <strong>{% trans 'membership for current year' %}</strong> :
                        {% if user.is_member %}
                            <span style="color:green">{% trans 'yes' %}</span>
                        {% else %}
                            <span style="color:red">{% trans 'no' %}</span>
                        {% endif %}
                    </li>
                </ul>

                <h3>{% trans 'Current borrowed items' %}</h3>
                {% if borrowed_items %}
                    <ul>
                        {% for emprunt in borrowed_items %}
                            <li>{{ emprunt.media }} ({% trans 'since' %} {{ emprunt.date_emprunt }})</li>
                        {% endfor %}
                    </ul>
                {% else %}
                    <p>{% trans 'No current borrowed items.' %}</p>
                {% endif %}

                <h3>{% trans 'My actions' %}</h3>
                {% load log %}
                {% get_admin_log 10 as admin_log for_user user %}
                {% if not admin_log %}
                    <p>{% trans 'None available' %}</p>
                {% else %}
                    <ul class="actionlist">
                        {% for entry in admin_log %}
                            <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
                                {% if entry.is_deletion or not entry.get_admin_url %}
                                    {{ entry.object_repr }}
                                {% else %}
                                    <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
                                {% endif %}
                                <br/>
                                {% if entry.content_type %}
                                    <span class="mini quiet">{% filter capfirst %}
                                        {{ entry.content_type }}{% endfilter %}</span>
                                {% else %}
                                    <span class="mini quiet">{% trans 'Unknown content' %}</span>
                                {% endif %}
                            </li>
                        {% endfor %}
                    </ul>
                {% endif %}
            {% else %}
                <p>{% trans 'You are not logged in.' %}</p>
            {% endif %}
        </div>
    </div>
{% endblock %}