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

{% set activeRouteKey = 'chill_person_view' %}

{% block title 'household.Household history for person'|trans %}

{% macro bloc_content(p) %}
    <div class="item-row">
        <div class="wrap-header">
            <div class="wh-row">
                <div class="wh-col">
                    <h3>
                        <i class="fa fa-home"></i>
                        <a href="{{ chill_path_add_return_path('chill_person_household_summary',{ 'household_id': p.household.id }) }}">
                            {{ 'household.Household number'|trans({'household_num': p.household.id }) }}
                        </a>
                    </h3>
                </div>
                <div class="wh-col">
                    Depuis le {{ p.startDate|format_date('long') }}
                </div>
            </div>
            <div class="wh-row">
                <div class="wh-col"></div>
                {% if p.endDate %}
                    <div class="wh-col">
                        Jusqu'au {{ p.endDate|format_date('long') }}
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="item-row separator">
        <div class="wrap-list">
            {% if p.household is same as p.person.getCurrentHousehold %}
                <div class="wl-row">
                    <div class="wl-col title">
                        <h3>{{ 'Address'|trans }}</h3>
                    </div>
                    <div class="wl-col list">
                        <p class="item">{{ p.household.getCurrentAddress|chill_entity_render_box }}</p>
                    </div>
                </div>
            {% endif %}
            <div class="wl-row">
                <div class="wl-col title">
                    <h3>{{ 'household.As member'|trans }}</h3>
                </div>
                <div class="wl-col list">
                    <p class="item">
                        {% if p.position %}
                            {{ p.position.label|localize_translatable_string }}
                        {% endif %}
                        {% if p.holder %}
                            <span class="fa-stack fa-holder" title="{{ 'houshold.holder'|trans|e('html_attr') }}">
                                <i class="fa fa-circle fa-stack-1x text-success"></i>
                                <i class="fa fa-stack-1x">T</i>
                            </span>
                        {% endif %}
                    </p>
                </div>
            </div>
            <div class="wl-row">
                <div class="wl-col title">
                    <h3>{{ 'household.Members at same time'|trans }}</h3>
                </div>
                <div class="wl-col list">
                    {% set simultaneous = p.household.getPersonsDuringMembership(p) %}
                    {% if simultaneous|length == 0 %}
                        <p class="chill-no-data-statement">
                            {{ 'household.Any simultaneous members'|trans }}
                        </p>
                    {% else %}
                        {% for person in simultaneous -%}
                            {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
                                action: 'show', displayBadge: true,
                                targetEntity: { name: 'person', id: person.id },
                                buttonText: person|chill_entity_render_string,
                                isDead: person.deathdate is not null
                            } %}
                        {%- endfor -%}
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
{% endmacro %}

{% block content %}
<div class="person-household">
    <h1>{{ 'household.Household history'|trans }}</h1>

    <div class="household_shared">
        <h2 class="chill-blue">{{ 'household.Household shared'|trans }}</h2>
        {% set memberships = person.getHouseholdParticipationsShareHousehold() %}

        {% if memberships|length == 0 %}
            <p class="chill-no-data-statement">{{ 'household.Never in any household'|trans }}</p>

            <ul class="record_actions">
                <li>
                    <a class="btn btn-misc" href="{{chill_path_add_return_path('chill_person_household_members_editor', { 'persons': [ person.id ]}) }}">
                        <i class="fa fa-sign-in fa-fw"></i>
                        {{ 'household.Join'|trans }}
                    </a>
                </li>
            </ul>

        {% else %}
            <div class="flex-table">
                {% for p in memberships %}
                    <div class="item-bloc">

                        {{ _self.bloc_content(p) }}

                        <div class="item-row separator">
                            <ul class="record_actions">
                                <li>
                                    <a href="{{ chill_path_add_return_path('chill_person_household_summary',{ 'household_id': p.household.id }) }}"
                                    class="btn btn-show" title="{{ 'Show'|trans }}"></a>
                                </li>
                                <li>
                                    <a href="{{ chill_path_add_return_path('chill_person_household_member_edit', { id: p.id }) }}"
                                       class="btn btn-edit" title="{{ 'Edit'|trans }}"></a>
                                </li>
                                {% if p.isCurrent() %}
                                    <li>
                                        <a class="btn btn-misc" href="{{ chill_path_add_return_path( 'chill_person_household_members_editor', { 'persons': [ person.id ], 'allow_leave_without_household': true }) }}">
                                            <i class="fa fa-scissors"></i>
                                            {{ 'household.Leave'|trans }}
                                        </a>
                                    </li>
                                {% endif %}
                            </ul>
                        </div>

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

            {% if not person.isSharingHousehold() %}
                <ul class="record_actions">
                    <li>
                        <a class="btn btn-misc" href="{{chill_path_add_return_path('chill_person_household_members_editor', { 'persons': [ person.id ], 'followAfter': true}) }}">
                            <i class="fa fa-sign-in fa-fw"></i>
                            {{ 'household.Join'|trans }}
                        </a>
                    </li>
                </ul>
            {% endif %}

        {% endif %}

    </div>
    <div class="household_not_shared">
        {% set memberships = person.getHouseholdParticipationsNotShareHousehold() %}
        {% if memberships|length > 0 %}

            <h2 class="chill-blue">{{ 'household.Household not shared'|trans }}</h2>

            <div class="flex-table">
                {% for p in memberships %}
                <div class="item-bloc">

                    {{ _self.bloc_content(p) }}

                    <div class="item-row separator">
                        <ul class="record_actions">
                            <li>
                                <a href="{{ chill_path_add_return_path('chill_person_household_member_edit', { id: p.id }) }}"
                                   class="btn btn-edit" title="{{ 'Edit'|trans }}"></a>
                            </li>
                        </ul>
                    </div>

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

</div>
{% endblock %}
