{% extends '@CoreShopFrontend/Checkout/layout.html.twig' %}
{% import '@CoreShopFrontend/Common/Macro/currency.html.twig' as currency %}
{% form_theme form 'bootstrap_4_layout.html.twig' %}

{% block checkout_title %}
    {{ 'coreshop.ui.shipping'|trans }}
{% endblock %}

{% block checkout %}
    <div class="card">
        <div class="card-header">
            {{ 'coreshop.ui.shipping'|trans }}
        </div>
        <div class="card-body">
            {{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
            {{ form_errors(form) }}

            {% set show_carrier_price = form.carrier.vars.show_carrier_price %}

            {% for key, carrier_form in form.carrier %}
                {% set carrier = form.carrier.vars.choices[key].data %}
                {% set price = form.carrier.vars.prices[carrier_form.vars.value] %}

                <div class="card">
                    <div class="card-header">
                        <div class="clearfix">
                            <div class="pull-left">
                                {{ form_widget(carrier_form, coreshop_test_form_attribute('carrier-select')|coreshop_merge_recursive({'label': false})) }}
                            </div>
                            <div class="pull-left">
                                <span {{ coreshop_test_html_attribute('carrier-label') }}>
                                    {{ carrier.title }}
                                </span>
                                {% if show_carrier_price %}
                                    <span {{ coreshop_test_html_attribute('carrier-price') }}>{{ currency.convertAndFormat(price) }}</span>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    {% if carrier.description %}
                        <div class="card-body">
                            {{ carrier.description }}
                        </div>
                    {% endif %}
                </div>
            {% endfor %}

            {{ form_row(form.comment, coreshop_test_form_attribute('shipping-comment')) }}

            <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-shipping-step') }}>
                        {{ 'coreshop.ui.proceed'|trans }}
                    </button>
                </div>
            </div>
            {{ form_end(form) }}
        </div>
    </div>
{% endblock %}
