{% 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 class="row">
            <div class="col-md">
                {{ 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>
            <div class="col-md-auto">
                <nav>
                    <a href="{{ path('sylius_shop_account_address_book_create') }}"
                       class="btn btn-primary btn-block btn-sm">{{ 'sylius.ui.add_address'|trans }}</a>
                    {{ sylius_template_event('sylius.shop.account.address_book.index.after_add_address_button', {'addresses': addresses}) }}
                </nav>
            </div>
        </div>
    </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 %}

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