{% extends "sco_page.j2" %}

{% block styles %}
    {{super()}}
    <link href="{{scu.STATIC_DIR}}/css/jury_but.css" rel="stylesheet" type="text/css" />
    <link href="{{scu.STATIC_DIR}}/css/cursus_but.css" rel="stylesheet" type="text/css" />
    <link href="{{scu.STATIC_DIR}}/css/bulletin_court.css" rel="stylesheet" type="text/css" />
{% endblock %}

{% macro table_modules(mod_type, title) -%}
<table class="resultats_modules">
    <thead>
        <tr class="titre_table">
            <th colspan="2"></th>
            <th colspan="{{ ues_acronyms|length }}">Unités d'enseignement</th>
        </tr>
        <tr class="titres_ues">
            <td colspan="2">{{title}}</td>
            {% for ue in ues_acronyms %}
                <td class="col_ue">{{ue}}</td>
            {% endfor %}
        </tr>
    </thead>       
    <tbody>
    {% for mod in bul[mod_type] %}
        <tr>
            <td>{{mod}}</td>
            <td>{{bul[mod_type][mod].titre}}</td>
            {% for ue in ues_acronyms %}
                <td>{{
                    bul.ues[ue][mod_type][mod].moyenne
                    if mod in bul.ues[ue][mod_type] else ""
                }}</td>
            {% endfor %}
        </tr>
    {% endfor %}
    </tbody>
</table>
{%- endmacro %}

{% block app_content %}

{% include 'bul_head.j2' %}

<div class="but_bul_court">
    {% if bul.options.show_abs %}
        <div id="assiduite">
            <div class="ligne-entete">Absences {{bul.semestre.absences.metrique}}</div>
            <div class="abs">Non justifiées</div>
            <div>{{bul.semestre.absences.injustifie}}</div>
            <div class="abs">Total</div>
            <div>{{bul.semestre.absences.total}}</div>
        </div>
    {% endif %}

    <div id="ues">
        <table>
        <thead>
            <tr class="titre_table">
                <th colspan="{{ 1 + bul.ues|length }}">Unités d'enseignement du semestre {{formsemestre.semestre_id}}</th>
            </tr>
            <tr class="titres_ues">
                <td></td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{ue}}</td>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Moyenne</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].moyenne.value}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>dont bonus</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].bonus if bul.ues[ue].bonus != "00.00" else ""}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>et malus</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].malus if bul.ues[ue].malus != "00.00" else ""}}</td>
                {% endfor %}
            </tr>
            <tr>
                <td>Rang</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{bul.ues[ue].moyenne.rang}} / {{bul.ues[ue].moyenne.total}}</td>
                {% endfor %}
            </tr>
            {% if prefs["bul_show_ects"] %}
                <tr>
                    <td>ECTS</td>
                    {% for ue in ues_acronyms %}
                        <td class="col_ue">{{
                            "%g"|format(bul["ues"][ue]["ECTS"]["acquis"]) if ue in bul["ues"] else ""
                        }} / {{
                            "%g"|format(bul["ues"][ue]["ECTS"]["total"]) if ue in bul["ues"] else ""
                        }}
                        </td>
                    {% endfor %}
                </tr>
            {% endif %}
            <tr class="jury">
                <td>Jury</td>
                {% for ue in ues_acronyms %}
                    <td class="col_ue">{{
                        decision_ues[ue].code if ue in decision_ues else ""
                    }}</td>
                {% endfor %}
            </tr>
        </tbody>
        </table>
    </div>

    <div id="ressources">
        {{ table_modules("ressources", "Ressources") }}
    </div>

    <div id="saes">
        {{ table_modules("saes", "Situations d'Apprentissage et d'Évaluation (SAÉ)") }}
    </div>

    <div id="row_situation">
        <div id="cursus_etud">
            {% include "but/cursus_etud.j2" %}
        </div>

        <div id="situation">
            <div>ECTS acquis en BUT&nbsp;: <b>{{"%g"|format(ects_total)}}</b></div>
            <div class="descr_jury">
                {% if bul.semestre.decision_annee %}
                    Décision saisie le {{
                        datetime.datetime.fromisoformat(bul.semestre.decision_annee.date).strftime("%d/%m/%Y")
                    }},
                    année <b>BUT{{bul.semestre.decision_annee.ordre}}</b>
                    <b>{{bul.semestre.decision_annee.code}}</b>.
                {% endif %}
                {% set virg = joiner(", ") %}
                {% for aut in bul.semestre.autorisation_inscription -%}
                    {% if loop.first %}
                        <br>Autorisé à s'inscrire en
                    {% endif %}
                    {{- virg() }}S{{aut.semestre_id -}}
                    {%- if loop.last -%}
                    .
                    {%- endif -%}
                {%- endfor %}
            </div>
        </div>
    </div>

    <div id="footer">
    Bulletin généré par ScoDoc le {{time.strftime("%d/%m/%Y à %Hh%M")}}. Explication des codes sur 
        <a href="https://scodoc.org/CodesJuryBUT">https://scodoc.org/CodesJuryBUT</a>
    </div>
</div>

{% endblock %}
