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

{% set activeRouteKey = 'chill_person_view' %}

{#
This view should receive those arguments:
- person
#}

{% block title %}{{ 'Person details'|trans|capitalize ~ ' ' ~ person|chill_entity_render_string }}{% endblock %}
{#
    we define variables to include an edit form repeated multiple time across
    the page
#}
{% set edit_tmp_name = '@ChillPerson/Form/go_to_form.html.twig'  %}
{% set edit_tmp_args = { 'form_path_args' : { 'person_id': person.id },
      'form_path_key' : 'chill_person_general_edit' } %}

{% block content %}
<div class="person-view">

    <div class="row">
        {% if person.memo is not empty and chill_person.fields.memo == 'visible' %}
        <div class="col-12">
            <figure class="person-details">
                <h2 class="chill-red">{{ 'Memo'|trans }}</h2>
                <div class="chill-user-quote">
                    {{ person.memo|chill_markdown_to_html }}
                </div>
            </figure>
        </div>
        {% endif %}

        <div class="col-sm-6 my-3">
            <figure class="person-details">
                <h2 class="chill-red">{{ 'General information'|trans }}</h2>
                <dl>
                    {% if person.civility is not null %}
                        <dt>{{ 'Civility'|trans }}&nbsp;:</dt>
                        <dd>
                        {% if person.civility.name|length > 0 %}
                        {{ person.civility.name|first }}
                        {% endif %}
                        </dd>
                    {% endif %}

                    <dt>{{ 'First name'|trans }}&nbsp;:</dt>
                    <dd>{{ person.firstName }}</dd>

                    <dt>{{ 'Last name'|trans }}&nbsp;:</dt>
                    <dd>{{ person.lastName }}</dd>
                    {% for el in person.altNames %}
                        {% if el.key in alt_names|keys %}
                            <dt>{{ alt_names[el.key]|localize_translatable_string }}&nbsp;:</dt>
                            <dd>{{ el.label }}</dd>
                        {% endif %}
                    {% endfor %}

                    <dt>{{ 'Gender'|trans }}&nbsp;:</dt>
                    {% if person.gender %}
                        <dd>{{ ( person.gender.label|localize_translatable_string ) }}</dd>
                    {% else %}
                        <dd>{{ 'gender.not defined'|trans }}</dd>
                    {% endif %}

                    {% if person.genderComment.comment is not empty %}
                        <dt>{{ 'Gender comment'|trans }}&nbsp;:</dt>
                        <dd>
                            <div class="chill-user-quote">
                                {{ person.genderComment.comment|chill_markdown_to_html }}
                            </div>
                        </dd>
                    {% endif %}

                </dl>
            </figure>
        </div>

        <div class="col-sm-6 my-3">
            <figure class="person-details">
                <h2 class="chill-green"><i class="fa fa-birthday-cake"></i>&nbsp;{{ 'Birth information'|trans }}</h2>
                <dl>
                    <dt>{{ 'Date of birth'|trans }}&nbsp;:</dt>
                    <dd>
                        {%- if person.birthdate is not null -%}
                        {{ person.birthdate|format_date('long') }}
                        {%- else -%}
                        <span class="chill-no-data-statement">{{ 'Unknown date of birth'|trans }}</span>
                        {%- endif -%}
                    </dd>

                    {%- if chill_person.fields.deathdate == 'visible' -%}
                        {%- if person.deathdate is not null -%}
                        <dt>{{ 'Date of death'|trans }}&nbsp;:</dt>
                        <dd>{{ person.deathdate|format_date('long') }}</dd>
                        {%- endif -%}
                    {%- endif -%}

                    {%- if chill_person.fields.place_of_birth == 'visible' -%}
                    <dt>{{ 'Place of birth'|trans }}&nbsp;:</dt>
                    {% if person.placeOfBirth is not empty %}
                        <dd>{{ person.placeOfBirth }}</dd>
                    {% else %}
                        <dd><span class="chill-no-data-statement">{{ 'Not given'|trans }}</span></dd>
                    {% endif %}
                    {%- endif -%}

                    {%- if chill_person.fields.country_of_birth == 'visible' -%}
                            <dt>{{ 'Country of birth'|trans }}&nbsp;:</dt>
                            <dd>{% apply spaceless %}
                                {% if person.countryOfBirth is not null %}
                                    {{ person.countryOfBirth.name|localize_translatable_string }}
                                {% else %}
                                    <span class="chill-no-data-statement">{{ 'Unknown country of birth'|trans }}</span>
                                {% endif %}
                            {% endapply %}</dd>
                    {%- endif -%}

                </dl>
            </figure>
        </div>

    </div>

    <div class="row">
        {%- if chill_person.fields.nationality == 'visible' or chill_person.fields.spoken_languages == 'visible'-%}
        <div class="col-sm-6 my-3">
            <figure class="person-details">
                <h2 class="chill-orange">{{ 'Administrative information'|trans }}</h2>

                {%- if chill_person.fields.nationality == 'visible' -%}
                <dl>
                    <dt>{{ 'Nationality'|trans }}&nbsp;:</dt>
                        <dd>
                            {% if person.nationality is not null %}
                                {{ person.nationality.name|localize_translatable_string }}
                            {% else %}
                                <span class="chill-no-data-statement">{{ 'Without nationality'|trans }}</span>
                            {% endif %}
                        </dd>
                </dl>
                {%- endif -%}
                {%- if chill_person.fields.spoken_languages == 'visible' -%}
                <dl>
                    <dt>{{'Spoken languages'|trans}}&nbsp;:</dt>
                    <dd>
                        {% if person.spokenLanguages|length == 0 %}
                            <span class="chill-no-data-statement">{{ 'Unknown spoken languages'|trans }}</span>
                        {% else %}
                            {% for lang in person.spokenLanguages %}
                                {{ lang.name|localize_translatable_string }}{% if not loop.last %},{% endif %}
                            {% endfor %}
                        {% endif %}
                    </dd>
                </dl>
                {%- endif -%}
                {% if chill_person.fields.administrative_status == 'visible' %}
                <dl>
                    <dt>{{ 'Administrative status'|trans }}&nbsp;:</dt>
                    <dd>
                    {% if person.administrativeStatus is not empty %}
                        {{ person.administrativeStatus.name|localize_translatable_string }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                    {% endif %}
                    </dd>
                </dl>
                {% endif %}
                {% if chill_person.fields.employment_status == 'visible' %}
                <dl>
                    <dt>{{ 'Employment status'|trans }}&nbsp;:</dt>
                    <dd>
                    {% if person.employmentStatus is not empty %}
                        {{ person.employmentStatus.name|localize_translatable_string }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                    {% endif %}
                    </dd>
                </dl>
                {% endif %}
                {%- if chill_person.fields.number_of_children == 'visible' -%}
                <dl>
                    <dt>{{'Number of children'|trans}}&nbsp;:</dt>
                    <dd>
                    {% if person.numberOfChildren is not null %}
                        {{ person.numberOfChildren }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                    {% endif %}
                    </dd>
                </dl>
                {%- endif -%}
                {%- if chill_person.fields.number_of_dependents == 'isible' -%}
                <dl>
                    <dt>{{'Number of dependents'|trans}}&nbsp;:</dt>
                    <dd>
                    {% if person.numberOfDependents is not null %}
                        {{ person.numberOfDependents }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                    {% endif %}
                    </dd>
                </dl>
                <dl>
                    <dt>{{'Number of dependents with disabilities'|trans}}&nbsp;:</dt>
                    <dd>
                    {% if person.numberOfDependents is not null %}
                        {{ person.numberOfDependentsWithDisabilities }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                    {% endif %}
                    </dd>
                </dl>
                {%- endif -%}
                {%- if chill_person.fields.marital_status == 'visible' -%}
                <dl>
                    <dt>{{'Marital status'|trans}}&nbsp;:</dt>
                    <dd>
                        {% if person.maritalStatus is not null %}
                            {{ person.maritalStatus.name|localize_translatable_string }}
                            {% if person.maritalStatusDate is not null %}
                                {{ 'person.from_the'|trans }} {{ person.maritalStatusDate|format_date('long') }}
                            {% endif %}
                        {% else %}
                            <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                        {% endif %}
                    </dd>
                    {% if person.maritalStatusComment.comment is not empty %}
                        <dt>{{ 'Comment on the marital status'|trans }}&nbsp;:</dt>
                        <dd>
                                <blockquote class="chill-user-quote">
                                    {{ person.maritalStatusComment.comment|chill_markdown_to_html }}
                                </blockquote>
                        </dd>
                    {% endif %}
                    {% for identifier in person.identifiers %}
                        {% if identifier.definition.isActive and (identifier|chill_entity_render_string) is not empty %}
                            <dt>{{ identifier.definition.label|localize_translatable_string }}&nbsp;:</dt>
                            <dd>{{ identifier|chill_entity_render_box }}</dd>
                        {% endif %}
                    {% endfor %}
                </dl>
                {%- endif -%}
            </figure>
        </div>
        {%- endif -%}

        {%- if chill_person.fields.email == 'visible'
            or chill_person.fields.phonenumber == 'visible'
            or chill_person.fields.mobilenumber == 'visible'
            or chill_person.fields.contact_info == 'visible' -%}
        <div class="col-sm-6 my-3">
            <figure class="person-details">
                <h2 class="chill-blue"><i class="fa fa-envelope-o"></i>&nbsp;{{ 'Contact information'|trans }}</h2>

                {%- if chill_person.fields.email == 'visible' -%}
                <dl>
                    <dt>{{ 'Email'|trans }}&nbsp;:</dt>
                    <dd>{% if person.email is not empty %}
                            <a href="{{ 'mailto:' ~ person.email }}" class="email">{{ person.email|nl2br }}</a>
                        {% else %}
                            <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                        {% endif %}
                    </dd>
                </dl>
                {%- endif -%}

                {%- if chill_person.fields.phonenumber == 'visible' -%}
                        <dl>
                            <dt>{{ 'Phonenumber'|trans }}&nbsp;:</dt>
                            <dd>{% if person.phonenumber is not empty %}<a href="tel:{{ person.phonenumber|phone_number_format('E164') }}">{{ person.phonenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
                        </dl>
                {% endif %}

                {%- if chill_person.fields.mobilenumber == 'visible' -%}
                <dl>
                    <dt>{{ 'Mobilenumber'|trans }}&nbsp;:</dt>
                    <dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber|phone_number_format('E164') }}">{{ person.mobilenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
                    <p>{% if person.acceptSMS %}{{ 'Accept short text message'|trans }}{% endif %}</p>
                </dl>
                {% endif %}

                {%- if chill_person.fields.mobilenumber == 'visible' -%}
                {% if person.otherPhoneNumbers is not empty %}
                <dl>
                    <dt>{{ 'Others phone numbers'|trans }}&nbsp;:</dt>
                    {% for el in person.otherPhoneNumbers %}
                        {% if el.phonenumber is not empty %}
                        <dd>{% if el.description is not empty %}{{ el.description }}&nbsp;:&nbsp;{% endif %}<a href="tel:{{ el.phonenumber|phone_number_format('E164') }}">{{ el.phonenumber|chill_format_phonenumber }}</a></dd>
                        {% endif %}
                    {% endfor %}
                </dl>
                {% endif %}
                {% endif %}

                {%- if chill_person.fields.contact_info == 'visible' -%}
                <dl>
                    <dt>{{ 'Notes on contact information'|trans }}&nbsp;:</dt>
                    <dd>
                        {% if person.contactInfo is not empty %}
                            <blockquote class="chill-user-quote">
                                {{ person.contactInfo|chill_markdown_to_html }}
                            </blockquote>
                        {% else %}
                            <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
                        {% endif %}
                    </dd>
                </dl>
                {%- endif -%}

            </figure>
        </div>
        {%- endif -%}

    </div>

    {% if cFGroup and (cFGroup.getActiveCustomFields|length > 0) %}
    <div class="row">
        <div class="col-12 custom-fields">
            <figure class="person-details">
                {{ chill_custom_fields_group_widget(person.cFData, cFGroup) }}
            </figure>
        </div>
    </div>

    <div class="row">
        <figure class="person-details"></figure>
    </div>
    {% endif %}

    <div>
        {% if person.createdBy %}
            <div class="createdBy">
                {{ 'Created by'|trans}}: <b>{{ person.createdBy|chill_entity_render_box({'at_date': person.createdAt}) }}</b>,<br>
                {{ 'on'|trans ~ person.createdAt|format_datetime('long', 'short') }}
            </div>
        {% endif %}
        {% if person.updatedBy %}
            {% import '@ChillPerson/Macro/updatedBy.html.twig' as macro %}
            {{ macro.updatedBy(person) }}
        {% endif %}
    </div>

    {% if is_granted('CHILL_PERSON_UPDATE', person) %}
    <ul class="sticky-form-buttons record_actions">
        <li>
            <a class="btn btn-update" href="{{ path('chill_person_general_edit', { 'person_id': person.id }) }}">
                {{ 'Edit'|trans }}
            </a>
        </li>
    </ul>
    {% endif %}

</div>
{% endblock %}
