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

{% from '@ChillBudget/Budget/_macros.html.twig' import table_elements, table_results %}

{% set activeRouteKey = '' %}
{% set title = 'Budget for household %household%'|trans({ '%household%' : household.id } ) %}
{% block title title %}

{% block js %}
{{ encore_entry_script_tags('page_budget') }}
{% endblock %}

{% block css %}
    {{ encore_entry_link_tags('page_budget') }}
{% endblock %}

{% block content %}
<h1>{{ title }}</h1>

{% include '@ChillBudget/Budget/_budget.html.twig' with {
    'resources': resources,
    'charges': charges,
    'household': household
} %}

    {#
<div class="my-4">
    <h4 class="family-title">{{ 'Budget calculator'|trans }}</h4>
    {{ table_results(wholeCharges, wholeResources) }}
</div>
#}

{% if household.getCurrentMembers|length > 0 %}
    <h1 class="my-5">{{ 'Budget household members'|trans }}</h1>

    {% for hm in household.getCurrentMembers %}
        {% set member = hm.person %}
        <div class="accordion" id="member_{{ member.id }}">
            <div class="accordion-item">
                <h2 class="accordion-header" id="heading_{{ member.id }}">
                    <button
                        class="accordion-button collapsed"
                        type="button"
                        data-bs-toggle="collapse"
                        data-bs-target="#collapse_{{ member.id }}"
                        aria-expanded="false"
                        aria-controls="collapse_{{ member.id }}">
                        <span class="folded">{{ 'Show budget of %name%'|trans({'%name%': member.firstName ~ " " ~ member.lastName }) }} ({{ 'budget.number of elements'|trans({ 'nb_items': member.getBudgetResources|length + member.getBudgetResources|length }) }})</span>
                        <span class="unfolded text-secondary">{{ 'Hide budget of %name%'|trans({'%name%': member.firstName ~ " " ~ member.lastName }) }}</span>
                    </button>
                </h2>

                <div id="collapse_{{ member.id }}"
                    class="accordion-collapse collapse"
                    aria-labelledby="heading_{{ member.id }}"
                    data-bs-parent="#nonCurrent">

                        <h2 class="mt-4">{{ 'Budget for %name%'|trans({'%name%': member.firstName ~ " " ~ member.lastName }) }}</h2>

                        {% include '@ChillBudget/Budget/_budget.html.twig' with {
                            'resources': member.getBudgetResources,
                            'charges': member.getBudgetCharges,
                            'person': member
                        } %}

                    <ul class="record_actions">
                        {% if is_granted('CHILL_BUDGET_ELEMENT_SEE', member) %}
                            <li class="btn-budget">
                                <a class="btn btn-edit" title={{ 'Edit budget'|trans }} href="{{ path('chill_budget_elements_index', { 'id': member.id } ) }}"></a>
                            </li>
                        {% endif %}
                    </ul>
                </div>
            </div>
        </div>
    {% endfor %}
{% endif %}

{% if is_granted('CHILL_BUDGET_ELEMENT_CREATE', household) %}
    <ul class="record_actions sticky-form-buttons">
        <li>
            <a class="btn btn-create" href="{{ path('chill_budget_resource_household_new', { 'id': household.id} ) }}">{{ 'Create new resource'|trans }}</a>
        </li>
        <li>
            <a class="btn btn-create" href="{{ path('chill_budget_charge_household_new', { 'id': household.id} ) }}">{{ 'Create new charge'|trans }}</a>
        </li>
    </ul>
{% endif %}


{% endblock %}

