{% extends "@ChillPerson/Person/layout.html.twig"  %}

{% set activeRouteKey = 'chill_person_duplicate' %}

{% block title %}{{ 'Person duplicate'|trans|capitalize ~ ' ' ~ person.firstName|capitalize ~
    ' ' ~ person.lastName }}{% endblock %}

{% block content %}
<div class="person-duplicate">
                        
            <h1>{{ title|default('Person duplicate')|trans }}</h1>

            {% if duplicatePersons|length > 0 %}
                <p>{{ title|default('Person duplicate explained')|trans }}</p>

                <table class="table table-bordered border-dark">
                <thead>
                    <tr>
                        <th class="chill-green">{% trans %}Name{% endtrans %}</th>
                        <th class="chill-green">{% trans %}Date of birth{% endtrans %}</th>
                        <th class="chill-green">{% trans %}Nationality{% endtrans %}</th>
                        <th>&nbsp;</th>
                    </tr>
                </thead>

                {% for duplicatePerson in duplicatePersons %}
                    <tr>
                        <td>
                            {% set is_open = duplicatePerson.isOpen() %}
                            <a href="{{ path('chill_person_view', { person_id : duplicatePerson.getId }) }}" {% if chill_person.fields.accompanying_period == 'visible' %}{% if is_open %} alt="{{ 'An accompanying period is open'|trans|e('html_attr') }}"{% else %} alt="{{ 'Any accompanying periods are open'|trans|e('html_attr') }}" {% endif %}{% endif %}>
                                {{ duplicatePerson|chill_entity_render_box }}
                                {% apply spaceless %}
                                    {% if chill_person.fields.accompanying_period == 'visible' %}
                                        {% if is_open == false %}
                                            <i class="fa fa-lock" ></i>
                                        {% else %}
                                            <i class="fa fa-unlock" ></i>
                                        {% endif %}
                                    {% endif %}
                                {% endapply %}
                            </a>
                        </td>
                        <td>
                            {% if duplicatePerson.birthdate is not null %}
                                {{ duplicatePerson.birthdate|format_date('long') }}
                            {% else %}
                                {{ 'Unknown date of birth'|trans }}
                            {% endif %}
                        </td>
                        <td>
                            {% if duplicatePerson.nationality is not null %}
                                {{ duplicatePerson.nationality.name|localize_translatable_string }}
                            {% else %}
                                {{ 'Without nationality'|trans }}
                            {% endif %}
                        </td>
                        <td>
                            <ul class="record_actions">
                                <li>
                                    <a class="btn btn-show" target="_blank" href="{{ path('chill_person_view', { person_id : duplicatePerson.id }) }}"></a>
                                </li>
                                <li>
                                    <a class="btn btn-action" href="{{ path('chill_person_duplicate_confirm', { person1_id : person.id, person2_id : duplicatePerson.id }) }}">
                                    <i class="fa fa-cog fa-fw"></i>{{ 'Merge'|trans }}</a>
                                </li>
                                <li>
                                    <a class="btn btn-misc" title="{{ 'Switch to truefalse'|trans }}"
                                        href="{{ path('chill_person_duplicate_not_duplicate', {person1_id : person.id, person2_id : duplicatePerson.id}) }}">
                                        <i class="fa fa-toggle-on fa-fw"></i>
                                        {{ 'duplicate'|trans }}
                                    </a>
                                </li>
                            </ul>
                        </td>
                    </tr>
                {% endfor %}
                </table>
            {% endif %}

            {% if notDuplicatePersons|length > 0 %}
                <h2>{{ 'Person flaged as duplicate' | trans }}</h2>
                <p>{{ 'Person flaged as duplicate explained' | trans }}</p>

                <table class="table table-bordered border-dark">
                    <thead>
                    <tr>
                        <th class="chill-orange">{% trans %}Name{% endtrans %}</th>
                        <th class="chill-orange">{% trans %}Date of birth{% endtrans %}</th>
                        <th class="chill-orange">{% trans %}Nationality{% endtrans %}</th>
                        <th>&nbsp;</th>
                    </tr>
                    </thead>

                    {% for notDuplicatePerson in notDuplicatePersons %}
                        <tr>
                            <td>
                                {% set is_open = notDuplicatePerson.isOpen() %}
                                <a href="{{ path('chill_person_view', { person_id : notDuplicatePerson.getId }) }}" {% if chill_person.fields.accompanying_period == 'visible' %}{% if is_open %} alt="{{ 'An accompanying period is open'|trans|e('html_attr') }}"{% else %} alt="{{ 'Any accompanying periods are open'|trans|e('html_attr') }}" {% endif %}{% endif %}>
                                    {{ notDuplicatePerson|chill_entity_render_box }}
                                    {% apply spaceless %}
                                        {% if chill_person.fields.accompanying_period == 'visible' %}
                                            {% if is_open == false %}
                                                <i class="fa fa-lock" ></i>
                                            {% else %}
                                                <i class="fa fa-unlock" ></i>
                                            {% endif %}
                                        {% endif %}
                                    {% endapply %}
                                </a>
                            </td>
                            <td>
                                {% if notDuplicatePerson.birthdate is not null %}
                                    {{ notDuplicatePerson.birthdate|format_date('long') }}
                                {% else %}
                                    {{ 'Unknown date of birth'|trans }}
                                {% endif %}
                            </td>
                            <td>
                                {% if notDuplicatePerson.nationality is not null %}
                                    {{ notDuplicatePerson.nationality.name|localize_translatable_string }}
                                {% else %}
                                    {{ 'Without nationality'|trans }}
                                {% endif %}
                            </td>
                            <td>
                                <ul class="record_actions">
                                    <li>
                                        <a class="btn btn-show" target="_blank" href="{{ path('chill_person_view', { person_id : notDuplicatePerson.id }) }}"></a>
                                    </li>
                                    <li>
                                        <a class="btn btn-misc" title="{{ 'Switch to duplicate'|trans }}"
                                           href="{{ path('chill_person_remove_duplicate_not_duplicate', {person1_id : person.id, person2_id : notDuplicatePerson.id}) }}">
                                           <i class="fa fa-toggle-off fa-fw"></i>
                                           {{ 'not-duplicate'|trans }}
                                       </a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            {% endif %}
                
            {% if notDuplicatePersons|length == 0 and duplicatePersons|length == 0 %}
                <span class="chill-no-data-statement">{{ 'No duplicate candidates'|trans }}</span>
            {% endif %}
                
            <ul class="record_actions sticky-form-buttons">
                <li class="cancel">
                    <a href="{{ path('chill_person_view', {person_id: person.id }) }}" class="btn btn-cancel">
                        {{ 'Return'|trans }}</a>
                </li>
                <li>
                    <a href="{{ path('chill_person_find_manually_duplicate', {person_id: person.id}) }}" class="btn btn-action">
                        {{ 'Associate manually a duplicate person' | trans }}
                    </a>
                </li>
            </ul>

</div>            
{% endblock %}
