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

{% set activeRouteKey = '' %}

{% block title %}{{ 'Residential addresses history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}{% endblock %}

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

    <h1>{{ 'Residential addresses history'|trans }}</h1>

    {% if is_granted('CHILL_PERSON_SEE', person) %}

        {% if addresses|length == 0 %}
            <span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>

        {% else %}
            <div class="flex-table">
            {% for a in addresses %}

                {% if a.address is not null %}
                    {% set kind = 'address' %}
                {% else %}
                    {% set kind = null %}
                {% endif %}

                <div class="item-bloc">
                    <div class="item-row">

                        <div class="item-col" style="width: 33%;">
                            <ul class="list-unstyled h3">
                                <li><span class="item-key">{{'Since'|trans}} : </span>{{ a.startDate|format_date('long') }}</li>
                                {% if a.endDate is not null %}
                                    <li><span class="item-key">{{'Until'|trans}} : </span><b>{{ a.endDate|format_date('long') }}</b></li>
                                {% endif %}
                            </ul>
                        </div>
                        <div class="item-col flex-column justify-content-start">
                            <div class="float-button top">
                                <div class="box">
                                    <div class="action">
                                        {% if is_granted('CHILL_PERSON_UPDATE', person) %}
                                            <a href="{{ path('chill_person_residential_address_edit', { 'id' : a.id, 'kind' : kind } ) }}" class="btn btn-update" title="{{ 'Update'|trans|e('html_attr') }}"></a>
                                            <a href="{{ path('chill_person_residential_address_delete', { 'id' : a.id, 'kind' : kind } ) }}" class="btn btn-delete" title="{{ 'Delete'|trans|e('html_attr') }}"></a>
                                        {% endif %}
                                    </div>
                                    <ul class="list-content fa-ul">
                                        {% if a.hostPerson is not null %}
                                        <li>
                                            <i class="fa fa-li fa-home"></i>
                                            <span class="item-key">{{ "Address of"|trans}} </span>
                                                {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
                                                    action: 'show', displayBadge: true,
                                                    targetEntity: { name: 'person', id: a.hostPerson.id },
                                                    buttonText: a.hostPerson|chill_entity_render_string,
                                                    isDead: a.hostPerson.deathdate is not null
                                                } %}
                                        </li>
                                        <li>
                                            {% set address_date = date(a.startDate|date("m/d/Y")) %}
                                            {% if a.hostPerson.getCurrentHouseholdAddress(a.endDate) is not null %}
                                                <i class="fa fa-li fa-map-marker"></i>
                                                {{ a.hostPerson.getCurrentHouseholdAddress(a.endDate)|chill_entity_render_box }}
                                            {% endif %}
                                        </li>
                                        {% elseif a.hostThirdParty is not null %}
                                        <li>
                                            <i class="fa fa-li fa-home"></i>
                                            <span class="item-key">{{ "Address of"|trans}}</span>
                                            {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
                                                action: 'show', displayBadge: true,
                                                targetEntity: { name: 'thirdparty', id: a.hostThirdParty.id },
                                                buttonText: a.hostThirdParty|chill_entity_render_string,
                                                isDead: false,
                                            } %}
                                        </li>
                                        <li>
                                            {% if a.hostThirdParty.address is not null %}
                                            <i class="fa fa-li fa-map-marker"></i>
                                            {{ a.hostThirdParty.address|chill_entity_render_box }}
                                            {% endif %}
                                        </li>
                                        {% else %}
                                        <li>
                                            {% if a.address is not null %}
                                                <i class="fa fa-li fa-map-marker"></i>
                                                {{ a.address|chill_entity_render_box }}
                                            {% endif %}
                                        {% endif %}
                                        </li>
                                    </ul>
                                    <div class="item-row">
                                        {% if not a.comment.isEmpty %}
                                            {{ a.comment|chill_entity_render_box }}
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            {% endfor %}
            </div>
        {% endif %}


    {% 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">
                {{ 'Back to the person details'|trans }}
            </a>
        </li>
        {% if is_granted('CHILL_PERSON_UPDATE', person) %}
        <li>
            <a class="btn btn-create"
                href="{{ path('chill_person_residential_address_new', { 'id' : person.id } ) }}">
                {{ 'Add a residential address'|trans }}
            </a>
        </li>
        {% endif %}
    </ul>
</div>
{% endblock %}
