{% 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-end">{% trans "Last name:" %}</dt>
            <dd class="col-sm-6">{{ user_object.last_name }}</dd>

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

            <dt class="col-sm-6 text-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-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-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-end">{% trans "Birth date:" %}</dt>
                    <dd class="col-sm-6">{{ user_object.registration.birth_date }}</dd>
                {% endif %}

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

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

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

                <dt class="col-sm-6 text-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>
            {% 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 %}
                    <dt class="col-sm-6 text-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>

                    <dt class="col-sm-6 text-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>

                    <dt class="col-sm-6 text-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>
                {% endif %}

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

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

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

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

                <dt class="col-sm-6 text-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 or user_object.registration.is_volunteer %}
                <dt class="col-sm-6 text-end">{% trans "Profesional activity:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.professional_activity }}</dd>

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

            <dt class="col-sm-6 text-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>
        </dl>

        {% if user_object.registration.participates and user_object.registration.team.participation.valid %}
            <hr>

            <dl class="row">
                <dt class="col-sm-6 text-end">{% trans "Payment information:" %}</dt>
                <dd class="col-sm-6">
                    {% trans "yes,no,pending" as yesnodefault %}
                    {% with info=user_object.registration.payment.additional_information %}
                        {% if info %}
                            <abbr title="{{ info }}">
                                {{ user_object.registration.payment.get_type_display }}, {% trans "valid:" %} {{ user_object.registration.payment.valid|yesno:yesnodefault }}
                            </abbr>
                        {% else %}
                            {{ user_object.registration.payment.get_type_display }}, {% trans "valid:" %} {{ user_object.registration.payment.valid|yesno:yesnodefault }}
                        {% endif %}
                        {% if user.registration.is_admin or user_object.registration.payment.valid is False %}
                            <button class="btn-sm btn-secondary" data-bs-toggle="modal" data-bs-target="#updatePaymentModal">
                                <i class="fas fa-money-bill-wave"></i> {% trans "Update payment" %}
                            </button>
                        {% endif %}
                        {% if user_object.registration.payment.type == "scholarship" %}
                            {% if user.registration.is_admin or user == user_object %}
                                <a href="{{ user_object.registration.payment.scholarship_file.url }}" class="btn btn-info">
                                    <i class="fas fa-file-pdf"></i> {% trans "Download scholarship attestation" %}
                                </a>
                            {% endif %}
                        {% endif %}
                    {% endwith %}
                </dd>
            </dl>
        {% 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" %}

        {% 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" %}

        {% 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" %}

        {% 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" %}

        {% 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 %}

    {% if user_object.registration.team.participation.valid %}
        {% trans "Update payment" as modal_title %}
        {% trans "Update" as modal_button %}
        {% url "registration:update_payment" pk=user_object.registration.payment.pk as modal_action %}
        {% include "base_modal.html" with modal_id="updatePayment" modal_additional_class="modal-xl" modal_enctype="multipart/form-data" %}
    {% 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 %}")
                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 %}

            {% if user_object.registration.team.participation.valid %}
                initModal("updatePayment", "{% url "registration:update_payment" pk=user_object.registration.payment.pk %}")
            {% endif %}
        });
    </script>
{% endblock %}
