{% extends "layout.html" %}
{% from "_macros.html" import render_roles, render_text_prop, render_location_prop, render_admin_unit_badges, render_fax_prop, render_logo, render_jquery_steps_header, render_phone_prop, render_email_prop, render_string_prop, render_field_with_errors, render_field, render_image_with_link, render_place, render_link_prop %}
{%- block title -%}
{{ request.source_admin_unit.name }}
{%- endblock -%}
{% block header_before_site_js %}
{{ render_jquery_steps_header() }}
<script>
$( function() {

    $('#acceptFormModal .btn-success').click(function() {
        $('#acceptFormModal form').submit();
    });

    $('#rejectFormModal .btn-danger').click(function() {
        $('#rejectFormModal form').submit();
    });
});
</script>
{% endblock %}
{% block content %}

<h1>{{ _('Review verification request') }}</h1>

<div class="mt-3 w-normal">
    <div class="card mb-3">
        <div class="card-header">
          {{ _('Organization') }}
        </div>
        <div class="card-body">
            <h5 class="card-title">{{ request.source_admin_unit.name }}{{ render_admin_unit_badges(request.source_admin_unit) }}</h5>

            {% if request.source_admin_unit.logo_id %}
                <div class="my-4">{{ render_logo(request.source_admin_unit.logo) }}</div>
            {% endif %}

            <div class="my-4">
                {{ render_link_prop(request.source_admin_unit.url) }}
                {{ render_email_prop(request.source_admin_unit.email) }}
                {{ render_phone_prop(request.source_admin_unit.phone) }}
                {{ render_fax_prop(request.source_admin_unit.fax) }}
                {{ render_location_prop(request.source_admin_unit.location) }}
                {% if request.source_admin_unit.description %}
                    <div class="my-2">
                        {{ render_text_prop(request.source_admin_unit.description) }}
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

    <div class="card mb-3">
        <div class="card-header">
          {{ _('Members') }}
        </div>
        <ul class="list-group list-group-flush">
            {% for member in request.source_admin_unit.members %}
                <li class="list-group-item">
                    <span>{{ member.user.email }}</span>
                    <small class="text-secondary">{{ render_roles(member.roles)}}</small>
                </li>
            {% endfor %}
        </ul>
    </div>

    <div class="d-flex justify-content-between my-4 decision-container">
        <button type="button" class="btn btn-success m-1" data-toggle="modal" data-target="#acceptFormModal"><i class="fa fa-check"></i> {{ _('Accept verification request') }}&hellip;</button>
        <button type="button" class="btn btn-danger m-1" data-toggle="modal" data-target="#rejectFormModal"><i class="fa fa-ban"></i> {{ _('Reject verification request') }}&hellip;</button>
    </div>

    <div class="modal fade" id="acceptFormModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ _('Accept verification request') }}</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form action="" method="POST">
                        {{ form.hidden_tag() }}
                        <input type="hidden" name="{{ form.review_status.name }}" value="2" />
                        <input type="hidden" name="{{ form.rejection_reason.name }}" value="0" />

                        {{ render_field_with_errors(form.auto_verify, ri="switch") }}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">{{ _('Cancel') }}</button>
                    <button type="button" class="btn btn-success">{{ _('Accept verification request') }}</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="rejectFormModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ _('Reject verification request') }}</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form action="" method="POST">
                        {{ form.hidden_tag() }}
                        <input type="hidden" name="{{ form.review_status.name }}" value="3" />

                        {{ render_field_with_errors(form.rejection_reason) }}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">{{ _('Cancel') }}</button>
                    <button type="button" class="btn btn-danger">{{ _('Reject verification request') }}</button>
                </div>
            </div>
        </div>
    </div>

</div>

{% endblock %}