{% form_theme form 'bootstrap_4_layout.html.twig' %}

<div class="card">
    <div class="card-header">
        {{ 'coreshop.ui.address'|trans }}
    </div>
    <div class="card-body">
        {% if form.invoiceAddress.vars.choices|length > 0 or form.shippingAddress.vars.choices|length > 0 %}
            {{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}

            {{ form_errors(form) }}

            <div class="row">

                <div class="col-12 col-sm-6 invoice-address-selector">
                    {{ form_row(form.invoiceAddress, coreshop_test_form_attribute('invoice-address')) }}
                </div>

                {% if hasShippableItems %}
                    {% set hideShipmentSelector = form.shippingAddress.vars.choices|length > 0 and form.useInvoiceAsShipping is defined and form.useInvoiceAsShipping.vars.data and form.shippingAddress.vars.valid != false %}
                    <div class="col-12 col-sm-6 shipping-address-selector" style="{% if hideShipmentSelector == true %} display:none; {% endif %}">
                        {{ form_row(form.shippingAddress, coreshop_test_form_attribute('shipping-address')) }}
                    </div>
                {% endif %}

            </div>

            {% if hasShippableItems %}
                <div class="row">
                    <div class="col-12">
                        {{ form_row(form.useInvoiceAsShipping, coreshop_test_form_attribute('use-invoice-as-shipping')) }}
                    </div>
                </div>
            {% endif %}

            <div class="row mb-4">

                <div class="col-12 col-sm-6">
                    <div class="card card-smart">
                        <div class="card-header">
                            <h4 class="card-title">
                                {{ 'coreshop.ui.invoice_address'|trans }}
                            </h4>
                        </div>
                        <div class="card-body panel-invoice-address mb-2">
                            <!-- filled by js -->
                        </div>
                        <div class="card-footer">
                            <a href="{{ path('coreshop_customer_address_new', {'_redirect': path('coreshop_checkout', {stepIdentifier: identifier}), address_identifier: 'invoice'}) }}"
                               class="btn btn-info pull-left">
                                {{ 'coreshop.ui.add_new_invoice_address'|trans }}
                            </a>
                        </div>
                    </div>
                </div>

                {% if hasShippableItems %}
                    <div class="col-12 col-sm-6">
                        <div class="card card-smart">
                            <div class="card-header">
                                <h4 class="card-title">
                                    {{ 'coreshop.ui.shipping_address'|trans }}
                                </h4>
                            </div>
                            <div class="card-body panel-shipping-address mb-2">
                                <!-- filled by js -->
                            </div>
                            <div class="card-footer d-none">
                                <a href="{{ path('coreshop_customer_address_new', {'_redirect': path('coreshop_checkout', {stepIdentifier: identifier}), address_identifier: 'shipping'}) }}"
                                   class="btn btn-info pull-left">
                                    {{ 'coreshop.ui.add_new_shipping_address'|trans }}
                                </a>
                            </div>
                        </div>
                    </div>
                {% endif %}

            </div>

            <div class="row">
                {% set previousStep = coreshop_checkout_steps_get_previous() %}
                {% if previousStep is not null %}
                    <div class="col-12 col-sm-6">
                        <a href="{{ path('coreshop_checkout', {'stepIdentifier': previousStep}) }}" class="btn btn-secondary">
                            {{ 'coreshop.ui.back'|trans }}
                        </a>
                    </div>
                {% endif %}
                <div class="col-12 {{ previousStep is not null ? 'col-sm-6' : '' }}">
                    <button type="submit" class="btn btn-success pull-right" {{ coreshop_test_html_attribute('submit-address-step') }}>
                        {{ 'coreshop.ui.proceed'|trans }}
                    </button>
                </div>
            </div>

            {{ form_end(form) }}

        {% else %}
            <p>{{ 'coreshop.ui.no_address_found'|trans }}</p>
            <div class="row">
                <div class="col-12">
                    <a href="{{ path('coreshop_customer_address_new', {'_redirect': path('coreshop_checkout', {stepIdentifier: identifier}), address_identifier: 'invoice'}) }}"
                       class="btn btn-info pull-left">
                        {{ 'coreshop.ui.add_new_invoice_address'|trans }}
                    </a>
                </div>
            </div>
        {% endif %}
    </div>
</div>