{% extends "base.html" %}

{% load i18n %}

{% block content %}
{% trans "any" as any %}
    <div class="card bg-light shadow">
        <div class="card-header text-center">
            <h4>{% trans "Participation of team" %} {{ participation.team.name }} ({{ participation.team.trigram }})</h4>
        </div>
        <div class="card-body">
            <dl class="row">
                <dt class="col-sm-2">{% trans "Team:" %}</dt>
                <dd class="col-sm-10"><a href="{% url "participation:team_detail" pk=participation.team.pk %}">{{ participation.team }}</a></dd>

                <dt class="col-sm-2">{% trans "Tournament:" %}</dt>
                <dd class="col-sm-10">
                    {% if participation.tournament %}
                        <a href="{% url "participation:tournament_detail" pk=participation.tournament.pk %}">{{ participation.tournament }}</a>
                    {% else %}
                        {% trans "any" %}
                    {% endif %}
                </dd>

                <dt class="col-sm-2">{% trans "Solutions:" %}</dt>
                <dd class="col-sm-10">
                    {% for solution in participation.solutions.all %}
                        <a href="{{ solution.file.url }}" data-turbolinks="false">{{ solution }}{% if not forloop.last %}, {% endif %}</a>
                    {% empty %}
                        {% trans "No solution was uploaded yet." %}
                    {% endfor %}
                </dd>

                {% if participation.pools.all %}
                    <dt class="col-sm-2">{% trans "Pools:" %}</dt>
                    <dd class="col-sm-10">
                        {% for pool in participation.pools.all %}
                            <a href="{{ pool.get_absolute_url }}" data-turbolinks="false">{{ pool }}{% if not forloop.last %}, {% endif %}</a>
                        {% endfor %}
                    </dd>
                {% endif %}
            </dl>
        </div>
        <div class="card-footer text-center">
            <button class="btn btn-primary" data-toggle="modal" data-target="#uploadSolutionModal">{% trans "Upload solution" %}</button>
        </div>
    </div>

    {% trans "Upload solution" as modal_title %}
    {% trans "Upload" as modal_button %}
    {% url "participation:upload_solution" pk=participation.pk as modal_action %}
    {% include "base_modal.html" with modal_id="uploadSolution" modal_enctype="multipart/form-data" %}
{% endblock %}

{% block extrajavascript %}
    <script>
        $(document).ready(function () {
            $('button[data-target="#uploadSolutionModal"]').click(function() {
                let modalBody = $("#uploadSolutionModal div.modal-body");
                if (!modalBody.html().trim())
                    modalBody.load("{% url "participation:upload_solution" pk=participation.pk %} #form-content")
            });
        });
    </script>
{% endblock %}
