{% extends 'layouts/base.html' %}

{% block title %}Главная{% endblock %}

{% block stylesheets %}
    <style>
        td > * {
            vertical-align : middle;
        }
    </style>
{% endblock %}

{% block content %}
    <div class="card border-0 shadow mb-4">
        <div class="card-body">
            <table>
                <tr>
                    <td>
                        <h1 class="h4">Мои группы</h1>
                    </td>
                    <td>
                        <button type="button" class="btn btn-block btn-info mb-3" data-bs-toggle="modal" data-bs-target="#modal-enter" style="margin-left: 10px;"><img height="15" width="15" src="/static/assets/img/icons/enter-group.svg" /></button>
                        <div class="modal fade" id="modal-enter" tabindex="-1" aria-labelledby="modal-default" style="display: none;" aria-hidden="true">
                              <div class="modal-dialog modal-dialog-centered" role="document">
                                  <div class="modal-content">
                                      <form method="POST">
                                          {% csrf_token %}
                                          <div class="modal-header">
                                              <h2 class="h6 modal-title">Присоединиться к группе</h2>
                                              <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                          </div>
                                          <div class="modal-body">
                                              <input type="text" style="width: 100%;" name="token" placeholder="Токен">
                                              <input type="hidden" name="action" value="token">
                                          </div>
                                          <div class="modal-footer">
                                              <button type="submit" class="btn btn-secondary">Войти</button>
                                              <button type="button" class="btn btn-link text-gray-600 ms-auto" data-bs-dismiss="modal">Закрыть</button>
                                          </div>
                                      </form>
                                  </div>
                              </div>
                        </div>
                    </td>
                    {% if user.userinfo.can_create %}
                        <td>
                            <button type="button" class="btn btn-block btn-success mb-3" data-bs-toggle="modal" data-bs-target="#modal-create" style="margin-left: 10px;"><img height="15" width="15" src="/static/assets/img/icons/plus.svg" /></button>
                            <div class="modal fade" id="modal-create" tabindex="-1" aria-labelledby="modal-default" style="display: none;" aria-hidden="true">
                                <div class="modal-dialog modal-dialog-centered" role="document">
                                    <div class="modal-content">
                                        <form method="POST">
                                            {% csrf_token %}
                                            <div class="modal-header">
                                                <h2 class="h6 modal-title">Создать группу</h2>
                                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                            </div>
                                            <div class="modal-body">
                                                <input type="text" style="width: 100%;" name="name" placeholder="Имя группы">
                                            </div>
                                            <div class="modal-footer">
                                                <button type="submit" class="btn btn-secondary">Создать</button>
                                                <button type="button" class="btn btn-link text-gray-600 ms-auto" data-bs-dismiss="modal">Закрыть</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </td>
                    {% endif %}
                </tr>
            </table>
            {% for group in groups %}
                <a href="/group?group_id={{ group.id }}">{{ group.name }}</a><br>
            {% endfor %}
        </div>
    </div>
    <div class="card border-0 shadow mb-4">
        <div class="card-body">
            <h1 class="h4">Топ задач сегодня</h1>
            {% for task in top_tasks_today %}
                <a href="/task?task_id={{ task.id }}">{{ task.name }} ({{ task.count }})</a> <span class="badge bg-{{ task.solution.badge_style }}">{{ task.solution.number_result }}</span><br>
            {% endfor %}
        </div>
    </div>
    {% if undone_tasks %}
        <div class="card border-0 shadow mb-4">
            <div class="card-body">
                <h1 class="h4">У тебя были попытки, попробуй решить задачи еще раз</h1>
                {% for task in undone_tasks %}
                    <a href="/task?task_id={{ task.id }}">{{ task.name }}</a>&emsp;<span class="badge bg-{{ task.solution.badge_style }}">{{ task.solution.number_result }}</span><br>
                {% endfor %}
            </div>
        </div>
    {% endif %}
    {% if new_tasks %}
        <div class="card border-0 shadow mb-4">
            <div class="card-body">
                <h1 class="h4">Новые задачи</h1>
                {% for task in new_tasks %}
                    <a href="/task?task_id={{ task.id }}">{{ task.name }}</a><br>
                {% endfor %}
            </div>
        </div>
    {% endif %}
    <div class="card border-0 shadow mb-4">
        <div class="card-body">
            <h1 class="h4">Топ пользователей</h1>
            {% for u in top_users %}
                <a href="/account?username={{ u.user.username }}">{{ u.place }}. <img src="{{ u.profile_pic_url }}" width="50px" height="50px" style="border-radius: 50%; margin-right: 10px;">{{ u.user.username }} ({{ u.rating }})</a><br><br>
            {% endfor %}
        </div>
    </div>
{% endblock %}