{% extends "base/base.html" %}
{% import "widgets/editor.html" as widget_editor %}
{% import "widgets/thread.html" as widget_thread with context %}
{% import "widgets/user.html" as widget_user %}
{% import "widgets/pagination.html" as widget_pagination with context %}
{% import "widgets/attachments.html" as widget_attachments %}


{% block title %}
<h1>Programme: {{ p.name }}</h1>
{% endblock %}

{% block content %}
<div id="program-banner">
</div>

<section>
    {% if p.thread.top_comment %}
        {% call widget_thread.thread_leader(p.thread.top_comment) %}
            <div class="info">
                {{ widget_thread.post_actions(p) }}
            </div>
            <h1>{{ p.name }}</h1>

            <div class="program-infos">
                <div>
                    <b>Posté :</b> {{ p.date_created | dyndate }}<br>
                    <b>Modifié :</b> {{ p.date_modified | dyndate }}<br>
                    <b>Version :</b> {{ p.version or "(non spécifié)" }}<br>
                    <b>Taille :</b> {{ p.size or "(non spécifié)" }}
                </div>
                <div>
                    Score au progrank: <span class="progrank" title="Dernière mise à jour : {{ p.progrank_date | dyndate }}">{{ p.progrank }}</span><br>
                    Tests : TODO (si si ça vient)<br>
                    [Lien pour soumettre un test]<br>
                    [Lien pour proposer au label]<br>
                    Total de téléchargements : TODO
                </div>
                <div class="program-tags">
                    {%- for tag in p.tags %}
                        <span class="tag tag-{{ tag.tag.category() }}">{{ tag.tag.pretty }}</span>
                    {% endfor -%}
                </div>
            </div>
            <hr>

            {% if p.event %}
                Ce programme a participé à l'événement <b>{{ p.event.name }}</b>!
                <hr>
            {% endif %}

            {{ p.thread.top_comment.text | md }}
            {{ widget_attachments.attachments(p.thread.top_comment) }}
        {% endcall %}
    {% endif %}

    {{ widget_pagination.paginate(comments, 'program_view', p) }}

    {{ widget_thread.thread(comments.items, p.thread.top_comment) }}

    {{ widget_pagination.paginate(comments, 'program_view', p) }}

    {% if V5Config.ENABLE_GUEST_POST or current_user.is_authenticated %}
    <div class=form>
        <h3>Commenter le programme</h3>
        <form action="" method="post" enctype="multipart/form-data">
            {{ form.hidden_tag() }}

            {% if form.pseudo %}
            <div>
                {{ form.pseudo.label }}
                {{ form.pseudo }}
                {% for error in form.pseudo.errors %}
                <span class="msgerror">{{ error }}</span>
                {% endfor %}
            {{ form.ab }}
            </div>
            {% endif %}

            {{ widget_editor.text_editor(form.message, label=False) }}

            <div>
                {{ form.attachments.label }}
                <div>
                    {{ form.attachments }}
                    {% for error in form.attachments.errors %}
                    <span class="msgerror">{{ error }}</span>
                    {% endfor %}
                </div>
            </div>

            <div>{{ form.submit(class_='bg-ok') }}</div>
        </form>
    </div>
    {% endif %}
{% endblock %}
