{% extends 'textrank/base.html' %}{% load i18n bootstrap4 %}

{% block content %}
<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{% url 'textrank:index' %}">TextRank</a></li>
        <li class="breadcrumb-item active" aria-current="page">{% trans 'Главная' %}</li>
    </ol>
</nav>

<div class="row">
    <div class="col-md-4">
        <h6>{% trans 'Регистрация слов' %}
            {% if result %}
            <small class="text-success"> {{ result.word }} </small>
            <small class="text-success">OK</small>
            {% endif %}
        </h6>
        <form class="form bg-light p-2" role="form" method="post" action="">
            {% csrf_token %}
            {{ form.non_field_errors }}
            {% for hidden in form.hidden_fields %}{{ hidden }}{% endfor %}
            {% for field in form.visible_fields %}{{ field|form_group }}{% endfor %}
            <button type="submit" class="btn btn-dark btn-block mt-1">{% trans 'Добавить' %}</button>
        </form>
    </div>

    <div class="col-md-8">
        <h6>{% trans 'Последние регистрации' %}</h6>
        <div class="table-responsive">
            <table class="table table-striped table-sm mb-3">
                <thead class="bg-dark text-white">
                    <tr>
                        <th>{% trans 'Слово' %}</th>
                        <th>{% trans 'Группа' %}</th>
                        <th class="text-right">{% trans 'Вес' %}</th>
                    </tr>
                </thead>
                <tbody>
                {% for weight in last_weights %}
                    <tr>
                        <td><a class="text-body" href="{% url 'textrank:keyword' id=weight.keyword.id %}">{{ weight.keyword }}</a></td>
                        <td><a class="text-body" href="{% url 'textrank:group' id=weight.group.id %}">{{ weight.group }}</a></td>
                        <td class="text-right">{{ weight.value }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    
        <div class="row">
            <div class="col-md-6">
                <h6>{% trans 'Последние группы' %}</h6>
                <div class="table-responsive">
                    <table class="table table-striped table-sm mb-3">
                        <thead class="bg-dark text-white">
                            <tr>
                                <th>{% trans 'Группа' %}</th>
                                <th>{% trans 'Редактор' %}</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for group in last_groups %}
                            <tr>
                                <td><a class="text-body" href="{% url 'textrank:group' id=group.id %}">{{ group.name }}</a></td>
                                <td>
                                {% if group.last_editor %}
                                    <a class="text-body" href="{% url 'textrank:groups' %}?last_editor={{ group.last_editor.id }}">{{ group.last_editor }}</a>
                                {% else %}
                                    <span>---</span>
                                {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="col-md-6">
                <h6>{% trans 'Сводка' %}</h6>
                <div class="table-responsive">
                    <table class="table table-striped table-sm mb-3">
                        <thead class="bg-dark text-white">
                            <tr>
                                <th></th>
                                <th class="text-right">{% trans 'Групп' %}</th>
                                <th class="text-right">{% trans 'Слов' %}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>{% trans 'Активных' %}</td>
                                <td class="text-right">{{ active_groups.count }}</td>
                                <td class="text-right">{{ active_keywords.count }}</td>
                            </tr>
                            <tr>
                                <td>{% trans 'Неактивных' %}</td>
                                <td class="text-right">{{ notactive_groups.count }}</td>
                                <td class="text-right">{{ notactive_keywords.count }}</td>
                            </tr>
                        </tbody>
                        <tfoot class="bg-secondary text-white">
                            <tr>
                                <td>{% trans 'Всего' %}</td>
                                <td class="text-right">{{ all_groups.count }}</td>
                                <td class="text-right">{{ all_keywords.count }}</td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}

{% block style_page %}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/css/selectize.bootstrap3.min.css" integrity="sha256-ze/OEYGcFbPRmvCnrSeKbRTtjG4vGLHXgOqsyLFTRjg=" crossorigin="anonymous" />
{% endblock %}

{% block javascript_page %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.min.js" integrity="sha256-+C0A5Ilqmu4QcSPxrlGpaZxJ04VjsRjKu+G82kl5UJk=" crossorigin="anonymous"></script>
<script>
var groups=[{% for g in active_groups %}{"value":"{{ g.name|escapejs }}","text":"{{ g.name|escapejs }}"},{% endfor %}];
$(document).ready(function($) {
    $('#id_groups').selectize({
        options: groups,
        create: true,
    })
{% if DEMO_MODE and not user.is_authenticated %}
    $('form').on('submit', function(e) {
        e.preventDefault()
        alert("{% trans 'Это демо-режим, авторизуйтесь, чтобы изменять данные.' %}")
    })
{% endif %}
})
</script>
{% endblock %}
