{#
 * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
 *
 * This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
#}
<div class="list-by-phonenumber">
    <h2>{{ title|default('Person search results by phonenumber')|trans }}</h2>

    <p>
        {{ 'total persons matching the search pattern'|trans({'total' : total}) }}&nbsp;:
        <a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="btn btn-sm">
            <i class="fa fa-search" aria-hidden="true"></i> {{ pattern }}
        </a>
    </p>

    <p>{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + persons|length, '%total%' : total } ) }}</p>

    {% if persons|length > 0 %}

        <table class="table table-bordered border-dark align-middle">
            <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 %}Phonenumber{% endtrans %}</th>
                    <th>&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                {% for person in persons %}
                    <tr>
                        <td>
                          {% set is_open = person.isOpen() %}
                          <a href="{{ path('chill_person_view', { person_id : person.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 %}>
                                {{person.firstName}} {{person.lastName}}
                                {% 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 person.birthdate is not null %}{{person.birthdate|format_date('long') }}{% else %}{{  'Unknown date of birth'|trans }}{% endif %}
                        </td>
                        <td class="person-list__--by-phonenumber__phones">
                            <ul>
                                {% if person.phonenumber is not empty %}
                                    <li>
                                        <a href="tel:{{ person.phonenumber|phone_number_format('E164') }}"><img src="{{ asset('build/images/mobile-alt-solid.svg') }}">&nbsp;<pre>{{ person.phonenumber|chill_format_phonenumber }}</pre></a>
                                    </li>
                                {% endif %}
                                {% if person.mobilenumber is not empty%}
                                    <li>
                                        <a href="tel:{{ person.mobilenumber|phone_number_format('E164') }}"><img src="{{ asset('build/images/phone-alt-solid.svg') }}">&nbsp;<pre>{{ person.mobilenumber|chill_format_phonenumber }}</pre></a>
                                    </li>
                                {% endif %}
                            </ul>
                        </td>
                        <td>
                            <ul class="record_actions">
                                <li><a class="btn btn-show" href="{{ path('chill_person_view', { person_id : person.getId }) }}"></a></li>
                                {% if is_granted('CHILL_PERSON_UPDATE', person) %}
                                <li><a class="btn btn-update" href="{{ path('chill_person_general_edit', { person_id : person.getId }) }}"></a></li>
                                {% endif %}
                            </ul>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

                <ul class="record_actions">
                    {% if is_granted('CHILL_PERSON_CREATE') %}
                    <li>
                        <a href="{{ path('chill_person_new') }}" class="btn btn-create">
                            {{ 'Add a person'|trans }}
                        </a>
                    </li>
                    {% endif %}
                    {% if preview == true and persons|length < total %}
                    <li>
                        <a href="{{ path('chill_main_search', { "name": search_name|default('abcd'), "q" : pattern }) }}" class="btn btn-misc">
                            {{ 'See all results'|trans }}
                        </a>
                    </li>
                    {% endif %}
                </ul>
    {% endif %}

    {% if preview == false %}
    {{ chill_pagination(paginator) }}
    {% endif %}
</div>
