{% import '@SyliusUi/Macro/headers.html.twig' as headers %}

{% extends '@SyliusShop/Account/AddressBook/layout.html.twig' %}

{% import '@SyliusUi/Macro/messages.html.twig' as messages %}

{% block subcontent %}
    <header class="account-address-book-header">
        <div>
            {{ headers.shop('sylius.ui.address_book'|trans, null, 'sylius.ui.manage_your_saved_addresses'|trans) }}
            {{ sylius_template_event('sylius.shop.account.address_book.index.after_content_header', {'addresses': addresses}) }}
        </div>

        <nav class="account-address-book-navigation">
            <a href="{{ path('sylius_shop_account_address_book_create') }}" class="btn btn-primary"><i class="fa fa-plus"></i>&nbsp;{{ 'sylius.ui.add_address'|trans }}</a>
            {{ sylius_template_event('sylius.shop.account.address_book.index.after_add_address_button', {'addresses': addresses}) }}
        </nav>
    </header>

    {% if addresses|length > 0 %}
        {% set default_address = (sylius.customer.defaultAddress) %}

        {% if default_address is not null %}
            {% include '@SyliusShop/Account/AddressBook/_defaultAddress.html.twig' with {'address': default_address} %}
        {% endif %}

        <hr>

        <div class="account-address-list" id="sylius-addresses" {{ sylius_test_html_attribute('addresses') }}>
            {% for address in addresses|filter(address => default_address is null or address.id != default_address.id) %}
                {% include '@SyliusShop/Account/AddressBook/_item.html.twig' %}
            {% endfor %}
        </div>
    {% else %}
        {{ messages.info('sylius.ui.you_have_no_addresses_defined') }}
    {% endif %}
{% endblock %}
