{% extends "base.html" %}

{% load i18n %}

{% block content %}
{% trans "any" as any %}

    <div class="card bg-body shadow">
        <div class="card-header text-center">
            <h4>{{ user_object.first_name }} {{ user_object.last_name }}</h4>
        </div>
    <div class="card-body">
        <dl class="row">
            <dt class="col-sm-6 text-sm-end">{% trans "Last name:" %}</dt>
            <dd class="col-sm-6">{{ user_object.last_name }}</dd>

            <dt class="col-sm-6 text-sm-end">{% trans "First name:" %}</dt>
            <dd class="col-sm-6">{{ user_object.first_name }}</dd>

            <dt class="col-sm-6 text-sm-end">{% trans "Email:" %}</dt>
            <dd class="col-sm-6"><a href="mailto:{{ user_object.email }}">{{ user_object.email }}</a>
                {% if not user_object.registration.email_confirmed %} (<em>{% trans "Not confirmed" %}, <a href="{% url "registration:email_validation_resend" pk=user_object.pk %}">{% trans "resend the validation link" %}</a></em>){% endif %}</dd>

            {% if user_object == user %}
                <dt class="col-sm-6 text-sm-end">{% trans "Password:" %}</dt>
                <dd class="col-sm-6">
                    <a href="{% url 'password_change' %}" class="btn btn-sm btn-secondary">
                        <i class="fas fa-edit"></i> {% trans "Change password" %}
                    </a>
                </dd>
            {% endif %}

            {% if user_object.registration.participates %}
                <dt class="col-sm-6 text-sm-end">{% trans "Team:" %}</dt>
                {% trans "any" as any %}
                <dd class="col-sm-6">
                    <a href="{% if user_object.registration.team %}{% url "participation:team_detail" pk=user_object.registration.team.pk %}{% else %}#{% endif %}">
                        {{ user_object.registration.team|default:any }}
                    </a>
                </dd>

                {% if user_object.registration.studentregistration %}
                    <dt class="col-sm-6 text-sm-end">{% trans "Birth date:" %}</dt>
                    <dd class="col-sm-6">{{ user_object.registration.birth_date }}</dd>
                {% endif %}

                <dt class="col-sm-6 text-sm-end">{% trans "Gender:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.get_gender_display }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Address:" %}</dt>
                <dd class="col-sm-6">
                    {{ user_object.registration.address }},
                    {{ user_object.registration.zip_code|stringformat:'05d' }} {{ user_object.registration.city }} ({{ user_object.registration.country }})
                </dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Phone number:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.phone_number }}</dd>

                {% if user_object.registration.health_issues %}
                    <dt class="col-sm-6 text-sm-end">{% trans "Health issues:" %}</dt>
                    <dd class="col-sm-6">{{ user_object.registration.health_issues }}</dd>
                {% endif %}

                {% if user_object.registration.housing_constraints %}
                    <dt class="col-sm-6 text-sm-end">{% trans "Housing constraints:" %}</dt>
                    <dd class="col-sm-6">{{ user_object.registration.housing_constraints }}</dd>
                {% endif %}

                <dt class="col-sm-6 text-sm-end">{% trans "Photo authorization:" %}</dt>
                <dd class="col-sm-6">
                    {% if user_object.registration.photo_authorization %}
                        <a href="{{ user_object.registration.photo_authorization.url }}">{% trans "Download" %}</a>
                    {% endif %}
                    {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadPhotoAuthorizationModal">{% trans "Replace" %}</button>
                    {% endif %}
                </dd>

                {% if user_object.registration.team.participation.final %}
                    <dt class="col-sm-6 text-sm-end">{% trans "Photo authorization (final):" %}</dt>
                    <dd class="col-sm-6">
                        {% if user_object.registration.photo_authorization_final %}
                            <a href="{{ user_object.registration.photo_authorization_final.url }}">{% trans "Download" %}</a>
                        {% endif %}
                        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadPhotoAuthorizationFinalModal">{% trans "Replace" %}</button>
                    </dd>
                {% endif %}
            {% endif %}

            {% if user_object.registration.studentregistration %}
                {% if user_object.registration.under_18 and user_object.registration.team.participation.tournament and not user_object.registration.team.participation.tournament.remote %}
                    {% if TFJM.HEALTH_SHEET_REQUIRED %}
                        <dt class="col-sm-6 text-sm-end">{% trans "Health sheet:" %}</dt>
                        <dd class="col-sm-6">
                            {% if user_object.registration.health_sheet %}
                                <a href="{{ user_object.registration.health_sheet.url }}">{% trans "Download" %}</a>
                            {% endif %}
                            {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                                <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadHealthSheetModal">{% trans "Replace" %}</button>
                            {% endif %}
                        </dd>
                    {% endif %}

                    {% if TFJM.VACCINE_SHEET_REQUIRED %}
                        <dt class="col-sm-6 text-sm-end">{% trans "Vaccine sheet:" %}</dt>
                        <dd class="col-sm-6">
                            {% if user_object.registration.vaccine_sheet %}
                                <a href="{{ user_object.registration.vaccine_sheet.url }}">{% trans "Download" %}</a>
                            {% endif %}
                            {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                                <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadVaccineSheetModal">{% trans "Replace" %}</button>
                            {% endif %}
                        </dd>
                    {% endif %}

                    <dt class="col-sm-6 text-sm-end">{% trans "Parental authorization:" %}</dt>
                    <dd class="col-sm-6">
                        {% if user_object.registration.parental_authorization %}
                            <a href="{{ user_object.registration.parental_authorization.url }}">{% trans "Download" %}</a>
                        {% endif %}
                        {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                            <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadParentalAuthorizationModal">{% trans "Replace" %}</button>
                        {% endif %}
                    </dd>

                    {% if user_object.registration.team.participation.final %}
                        <dt class="col-sm-6 text-sm-end">{% trans "Parental authorization (final):" %}</dt>
                        <dd class="col-sm-6">
                            {% if user_object.registration.parental_authorization_final %}
                                <a href="{{ user_object.registration.parental_authorization_final.url }}">{% trans "Download" %}</a>
                            {% endif %}
                            <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadParentalAuthorizationFinalModal">{% trans "Replace" %}</button>
                        </dd>
                    {% endif %}
                {% endif %}

                <dt class="col-sm-6 text-sm-end">{% trans "Student class:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.get_student_class_display }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "School:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.school }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Responsible name:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.responsible_name }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Responsible phone number:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.responsible_phone }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Responsible email address:" %}</dt>
                {% with user_object.registration.responsible_email as email %}
                    <dd class="col-sm-6"><a href="mailto:{{ email }}">{{ email }}</a></dd>
                {% endwith %}
            {% elif user_object.registration.coachregistration %}
                <dt class="col-sm-6 text-sm-end">{% trans "Scientific coach:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.is_scientific_coach|yesno }}</dd>
                
                <dt class="col-sm-6 text-sm-end">{% trans "Accompanying coach:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.is_accompanying_coach|yesno }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Most recent degree:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.last_degree }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Professional activity:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.professional_activity }}</dd>

            {% elif user_object.registration.is_volunteer %}
                <dt class="col-sm-6 text-sm-end">{% trans "Professional activity:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.professional_activity }}</dd>

                <dt class="col-sm-6 text-sm-end">{% trans "Admin:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.is_admin|yesno }}</dd>
            {% endif %}

            {% if TFJM.SUGGEST_ANIMATH %}
                <dt class="col-sm-6 text-sm-end">{% trans "Grant Animath to contact me in the future about other actions:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.give_contact_to_animath|yesno }}</dd>
            {% endif %}
        </dl>

        {% if TFJM.PAYMENT_MANAGEMENT and user_object.registration.participates and user_object.registration.team.participation.valid %}
            <hr>
            {% for payment in user_object.registration.payments.all %}
                <dl class="row">
                    <dt class="col-sm-6 text-sm-end">
                        {% if payment.final %}
                            {% trans "Payment information (final):" %}
                        {% else %}
                            {% trans "Payment information:" %}
                        {% endif %}
                    </dt>
                    <dd class="col-sm-6">
                        {% trans "yes,no,pending" as yesnodefault %}
                        {% with info=payment.additional_information %}
                            {% if info %}
                                <abbr title="{{ info }}">
                                    {{ payment.get_type_display }}, {% trans "valid:" %} {{ payment.valid|yesno:yesnodefault }}
                                </abbr>
                            {% else %}
                                {{ payment.get_type_display }}, {% trans "valid:" %} {{ payment.valid|yesno:yesnodefault }}
                            {% endif %}
                            {% if user.registration.is_volunteer or payment.valid is False %}
                                <a href="{% url "registration:update_payment" pk=payment.pk %}" class="btn btn-secondary">
                                    <i class="fas fa-money-bill-wave"></i> {% trans "Update payment" %}
                                </a>
                            {% endif %}
                            {% if payment.type == "scholarship" or payment.type == "bank_transfer" %}
                                {% if user.registration.is_admin or user == user_object %}
                                    <a href="{{ payment.receipt.url }}" class="btn btn-info">
                                        <i class="fas fa-file-pdf"></i>
                                        {% if payment.type == "scholarship" %}
                                            {% trans "Download scholarship attestation" %}
                                        {% elif payment.type == "bank_transfer" %}
                                            {% trans "Download bank transfer receipt" %}
                                        {% endif %}
                                    </a>
                                {% endif %}
                            {% endif %}
                        {% endwith %}
                    </dd>
                </dl>
            {% endfor %}
        {% endif %}
    </div>
    {% if user.pk == user_object.pk or user.registration.is_admin %}
        <div class="card-footer text-center">
            <a class="btn btn-primary" href="{% url "registration:update_user" pk=user_object.pk %}">{% trans "Update" %}</a>
            {% if user.registration.is_admin %}
                <a class="btn btn-info" href="{% url "registration:user_impersonate" pk=user_object.pk %}">{% trans "Impersonate" %}</a>
            {% endif %}
        </div>
    {% endif %}
    </div>

    {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
        {% trans "Upload photo authorization" as modal_title %}
        {% trans "Upload" as modal_button %}
        {% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk as modal_action %}
        {% include "base_modal.html" with modal_id="uploadPhotoAuthorization" modal_enctype="multipart/form-data" %}

        {% if user_object.registration.under_18 %}
            {% if TFJM.HEALTH_SHEET_REQUIRED %}
                {% trans "Upload health sheet" as modal_title %}
                {% trans "Upload" as modal_button %}
                {% url "registration:upload_user_health_sheet" pk=user_object.registration.pk as modal_action %}
                {% include "base_modal.html" with modal_id="uploadHealthSheet" modal_enctype="multipart/form-data" %}
            {% endif %}

            {% if TFJM.VACCINE_SHEET_REQUIRED %}
                {% trans "Upload vaccine sheet" as modal_title %}
                {% trans "Upload" as modal_button %}
                {% url "registration:upload_user_vaccine_sheet" pk=user_object.registration.pk as modal_action %}
                {% include "base_modal.html" with modal_id="uploadVaccineSheet" modal_enctype="multipart/form-data" %}
            {% endif %}

            {% trans "Upload parental authorization" as modal_title %}
            {% trans "Upload" as modal_button %}
            {% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk as modal_action %}
            {% include "base_modal.html" with modal_id="uploadParentalAuthorization" modal_enctype="multipart/form-data" %}
        {% endif %}
    {% endif %}

    {% if user_object.registration.team.participation.final %}
        {% trans "Upload photo authorization (final)" as modal_title %}
        {% trans "Upload" as modal_button %}
        {% url "registration:upload_user_photo_authorization_final" pk=user_object.registration.pk as modal_action %}
        {% include "base_modal.html" with modal_id="uploadPhotoAuthorizationFinal" modal_enctype="multipart/form-data" %}

        {% if user_object.registration.under_18_final %}
            {% trans "Upload parental authorization (final)" as modal_title %}
            {% trans "Upload" as modal_button %}
            {% url "registration:upload_user_parental_authorization_final" pk=user_object.registration.pk as modal_action %}
            {% include "base_modal.html" with modal_id="uploadParentalAuthorizationFinal" modal_enctype="multipart/form-data" %}
        {% endif %}
    {% endif %}
{% endblock %}

{% block extrajavascript %}
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                initModal("uploadPhotoAuthorization", "{% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk %}")
                {% if user_object.registration.under_18 %}
                    initModal("uploadHealthSheet", "{% url "registration:upload_user_health_sheet" pk=user_object.registration.pk %}")
                    initModal("uploadVaccineSheet", "{% url "registration:upload_user_vaccine_sheet" pk=user_object.registration.pk %}")
                    initModal("uploadParentalAuthorization", "{% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk %}")
                {% endif %}
            {% endif %}

            {% if user_object.registration.team.participation.final %}
                initModal("uploadPhotoAuthorizationFinal", "{% url "registration:upload_user_photo_authorization_final" pk=user_object.registration.pk %}")
                 {% if user_object.registration.under_18_final %}
                     initModal("uploadParentalAuthorizationFinal", "{% url "registration:upload_user_parental_authorization_final" pk=user_object.registration.pk %}")
                 {% endif %}
            {% endif %}
        });
    </script>
{% endblock %}
