{% extends "base.html" %}

{% load i18n %}

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

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

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

            <dt class="col-sm-6 text-right">{% 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-right">{% trans "Password:" %}</dt>
                <dd class="col-sm-6">
                    <a href="{% url 'password_change' %}" class="btn-sm btn-secondary" data-turbolinks="false">
                        <i class="fas fa-edit"></i> {% trans "Change password" %}
                    </a>
                </dd>
            {% endif %}

            {% if user_object.registration.participates %}
                <dt class="col-sm-6 text-right">{% 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>

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

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

                <dt class="col-sm-6 text-right">{% trans "Address:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.address }}</dd>

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

                <dt class="col-sm-6 text-right">{% trans "Health issues:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.health_issues|default:any }}</dd>

                <dt class="col-sm-6 text-right">{% trans "Photo authorization:" %}</dt>
                <dd class="col-sm-6">
                    {% if user_object.registration.photo_authorization %}
                        <a href="{{ user_object.registration.photo_authorization.url }}" data-turbolinks="false">{% trans "Download" %}</a>
                    {% endif %}
                    {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                        <button class="btn btn-primary" data-toggle="modal" data-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-right">{% trans "Health sheet:" %}</dt>
                    <dd class="col-sm-6">
                        {% if user_object.registration.health_sheet %}
                            <a href="{{ user_object.registration.health_sheet.url }}" data-turbolinks="false">{% trans "Download" %}</a>
                        {% endif %}
                        {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                            <button class="btn btn-primary" data-toggle="modal" data-target="#uploadHealthSheetModal">{% trans "Replace" %}</button>
                        {% endif %}
                    </dd>

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

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

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

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

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

                <dt class="col-sm-6 text-right">{% 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.is_admin %}
                <dt class="col-sm-6 text-right">{% trans "Role:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.role }}</dd>
            {% elif user_object.registration.coachregistration or user_object.registration.is_volunteer %}
                <dt class="col-sm-6 text-right">{% trans "Profesional activity:" %}</dt>
                <dd class="col-sm-6">{{ user_object.registration.professional_activity }}</dd>
            {% endif %}

            <dt class="col-sm-6 text-right">{% 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-right">{% 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-toggle="modal" data-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" data-turbolinks="false">
                                    <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 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).ready(function() {
            {% if user_object.registration.team and not user_object.registration.team.participation.valid %}
                $('button[data-target="#uploadPhotoAuthorizationModal"]').click(function() {
                    let modalBody = $("#uploadPhotoAuthorizationModal div.modal-body");
                    if (!modalBody.html().trim())
                        modalBody.load("{% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk %} #form-content");
                });
                $('button[data-target="#uploadHealthSheetModal"]').click(function() {
                    let modalBody = $("#uploadHealthSheetModal div.modal-body");
                    if (!modalBody.html().trim())
                        modalBody.load("{% url "registration:upload_user_health_sheet" pk=user_object.registration.pk %} #form-content");
                });
                $('button[data-target="#uploadParentalAuthorizationModal"]').click(function() {
                    let modalBody = $("#uploadParentalAuthorizationModal div.modal-body");
                    if (!modalBody.html().trim())
                        modalBody.load("{% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk %} #form-content");
                });
            {% endif %}
            {% if user_object.registration.team.participation.valid %}
                $('button[data-target="#updatePaymentModal"]').click(function() {
                    let modalBody = $("#updatePaymentModal div.modal-body");
                    if (!modalBody.html().trim())
                        modalBody.load("{% url "registration:update_payment" pk=user_object.registration.payment.pk %} #form-content");
                });
            {% endif %}
        });
    </script>
{% endblock %}
