{% extends '@CoreShopFrontend/layout-full.html.twig' %}

{% block center %}
<div id="main-container" class="container p-0">

    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ path('coreshop_index') }}">{{ 'coreshop.ui.home'|trans }}</a></li>
            <li class="breadcrumb-item"><a href="{{ path('coreshop_customer_profile') }}">{{ 'coreshop.ui.profile'|trans }}</a></li>
            <li class="breadcrumb-item"><a href="{{ path('coreshop_customer_addresses') }}">{{ 'coreshop.ui.addresses'|trans }}</a></li>
            <li class="breadcrumb-item active">{{ 'coreshop.ui.address'|trans }}</li>
        </ol>
    </nav>

    <h2 class="main-heading text-center">
        {{ 'coreshop.ui.addresses'|trans }}
    </h2>

    {% include '@CoreShopFrontend/Common/flash_messages.html.twig' %}

    <section class="addresses-area">
        <div class="row mb-4">
            {% for address in customer|coreshop_allocate_valid_addresses %}
                <div class="col-6">
                    <div class="card card-smart">
                        <div class="card-body">
                            {% if customer is not coreshop_address_owner_of(address) %}
                                <span class="badge badge-secondary float-right">{{ 'coreshop.ui.company_address'|trans }}</span>
                            {% elseif address.addressIdentifier is not empty %}
                                <span class="badge badge-secondary float-right">{{ ('coreshop.ui.' ~ address.addressIdentifier.name ~ '_address')|trans }}</span>
                            {% endif %}
                            {{ address|coreshop_format_address }}
                            <br/>
                            <br/>
                            {% if is_granted('CORESHOP_CUSTOMER_PROFILE_ADDRESS_EDIT') %}
                                <a href="{{ path('coreshop_customer_address_edit', {name: address.street, address: address.id|coreshop_string}) }}" class="btn btn-success" {{ coreshop_test_html_attribute('addresses-link',  address.street) }}>
                                    {{ 'coreshop.ui.edit'|trans }}
                                </a>
                            {% endif %}

                            {% if is_granted('CORESHOP_CUSTOMER_PROFILE_ADDRESS_DELETE') %}
                                <a href="{{ path('coreshop_customer_address_delete', {address: address.id|coreshop_string}) }}" class="btn btn-danger" {{ coreshop_test_html_attribute('address-delete',  address.street) }}>
                                    {{ 'coreshop.ui.delete'|trans }}
                                </a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>

        {% if is_granted('CORESHOP_CUSTOMER_PROFILE_ADDRESS_ADD') %}
            <div class="row">
                <div class="col-12">
                    <a href="{{ path('coreshop_customer_address_new') }}" class="btn btn-success" {{ coreshop_test_html_attribute('address-add') }}>
                        {{ 'coreshop.ui.add_new_address'|trans }}
                    </a>
                </div>
            </div>
        {% endif %}
    </section>
</div>
{% endblock %}
