{% extends 'base_main.html' %}

{% block title %}Задачи{% endblock %}

{% load filters %}

{% block main %}
    <table>
        <tr>
            <td>
                <h2>Задачи</h2>
            </td>
            {% if user.userinfo.can_create %}
                <td>
                    <button style="margin-left: 20px;" class="btn btn-success" data-toggle="modal" data-target="#example"><i class="fa fa-plus"></i></button>
                <div class="modal fade" id="example" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
              <div class="modal-dialog" role="document">
              <form method="POST">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLongTitle">Создать новую задачу</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-12">
                            {% csrf_token %}
                            <input type="text" name="name" placeholder="Название задачи">
                            </div>
                        </div>
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times-circle"></i> Закрыть</button>
                    <button type="submit" class="btn btn-success"><i class="fa fa-plus-circle"></i> Создать</button>
                  </div>
                </div>
              </form>
              </div>
            </div>
                </td>
            {% endif %}
        </tr>
    </table>
    {% for task in user.userinfo.available_tasks %}
        {% with result=user|solved:task %}
            <a href="/task?task_id={{ task.id }}" style="color: {% if result %}green{% else %}{% if result == False %}red{% else %}#307df6{% endif %}{% endif %};">{{ task.name }}</a> {% if task.creator == user or user.username in task.editors %}<a href="/admin/task?task_id={{ task.id }}"><i class="fa fa-pencil"></i> </a><a href="/solutions?task_id={{ task.id }}"><i class="fa fa-stack-overflow"></i> </a>{% endif %}<br>
        {% endwith %}
    {% endfor %}
{% endblock %}