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

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

{% block title %}{{ 'sylius.ui.address_book'|trans }} | {{ parent() }}{% endblock %}

{% block subcontent %}
    <div class="ui stackable two column grid">
        <div class="column">
            <h1 class="ui header">
                {{ 'sylius.ui.address_book'|trans }}
                <div class="sub header">{{ 'sylius.ui.manage_your_saved_addresses'|trans }}</div>
            </h1>

            {{ sylius_template_event('sylius.shop.account.address_book.index.after_content_header', {'addresses': addresses}) }}
        </div>
        <div class="middle aligned column">
            <a href="{{ path('sylius_shop_account_address_book_create') }}" class="ui right floated blue button"><i class="circle plus icon"></i> {{ 'sylius.ui.add_address'|trans }}</a>

            {{ sylius_template_event('sylius.shop.account.address_book.index.after_add_address_button', {'addresses': addresses}) }}
        </div>
    </div>

    {% 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="ui stackable grid" 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 %}
