{% extends 'site/base.html' %}
{% load i18n %}

{% block content %}
<main class="account">
    {% include 'site/fragment_messages.html' %}
    <h2>{% trans 'Report' %}: {{ report.title }}</h2>
    <p>
        <a href="{% url 'site.report_list' filter='all' %}">{% trans 'show all reports' %}</a> –
        <a href="{% url 'site.report_list' filter='open' %}">{% trans 'show open reports' %}</a>
    </p>
    <p>
        <em>
            {% if report.open %}
                <strong class="green">{% trans 'open' %}</strong>
            {% else %}
                <strong class="red">{% trans 'closed' %}</strong>
            {% endif %}
            –
            {% if report.author %}
                {% trans 'by' %} {{ report.author.username }}
            {% else %}
                {% trans 'anonymous submission' %}
            {% endif %}
            –
            {{ report.created }}
        </em>
        <br>
        <a href="{% url 'site.report_detail' pk=report.pk secret=report.secret %}">{% trans 'public URL to this report' %}</a>
    </p>
    {% include 'site/fragment_report_meta.html' %}

    {% for field in form %}
        {% if field.name != 'title' %}
        <p>
            <strong>{{ field.label }}:</strong><br>
            {% if field.name == 'description' %}
                {{ report.description | linebreaksbr }}
            {% elif field.name == 'created_groups' %}
                {% for group in report.created_groups.all %}
                    {{ group.title }}<br>
                {% empty %}
                    <em>{% trans '(none)' %}</em>
                {% endfor %}
            {% else %}
                {{ field.value }}
            {% endif %}
        </p>
        {% endif %}
    {% endfor %}

    {% for update in report.updates.all %}
        {% if update_form or update.public or update.open != None %}
            <hr>
            <p><em>{{ update.datetime }}</em> – {{ update.author.username }}</p>
            {% if update.open == True %}
                <p>{% trans 'Issue was opened.' %}</p>
            {% elif update.open == False %}
                <p>{% trans 'Issue was closed.' %}</p>
            {% endif %}
            {% if update.comment %}
                {% if update.public or update_form %}
                    <blockquote>{{ update.comment|linebreaksbr }}</blockquote>
                {% endif %}
                {% if update.public and update_form %}
                    {% trans '(public)' %}
                {% endif %}
            {% endif %}
        {% endif %}

    {% endfor %}

    {% if update_form %}
        <hr>
        <form method="post">
            {% csrf_token %}
            <h3>{% trans 'Update issue' %}</h3>
            {{ update_form }}
            <p><button type="submit">{% trans 'Submit' %}</button></p>
        </form>
    {% endif %}
</main>
{% endblock %}
