{% extends '@CoreShopFrontend/Order/layout.html.twig' %}
{% import "@CoreShopFrontend/Common/Macro/messages.html.twig" as messages %}
{% form_theme form 'bootstrap_4_layout.html.twig' %}

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

{% block order %}

    {% include '@CoreShopFrontend/Common/order_detail.html.twig' with {order: order} only %}

    {% if order.paymentState in ['awaiting_payment'] %}

        {% if payment is not null %}
            {% if payment.details.coreshop_payment_note is defined %}
                {{ messages.info(payment.details.coreshop_payment_note) }}
            {% elseif payment.state == 'cancelled' %}
                {{ messages.info('coreshop.ui.order.revise.transaction_cancelled') }}
            {% elseif payment.state == 'failed' %}
                {{ messages.info('coreshop.ui.order.revise.transaction_failed') }}
            {% endif %}
        {% endif %}

        {{ form_start(form, {'action': path('coreshop_order_revise', {'token': order.token}), 'attr': {'novalidate': 'novalidate'}}) }}

        {{ form_row(form.paymentProvider) }}

        <div class="paymentSettings">
            {% if form.paymentSettings is defined %}
                {% for field in form.paymentSettings %}
                    {{ form_row(field) }}
                {% endfor %}
            {% endif %}
        </div>

        {% for name, paymentSettingConfigurationPrototype in form.vars.prototypes %}
            <div id="{{ form.paymentProvider.vars.id }}_{{ name }}" data-container=".configuration"
                 data-prototype="{{ form_widget(paymentSettingConfigurationPrototype)|e }}">
            </div>
        {% endfor %}

        <div class="row">
            <div class="col-12 col-sm-6">
                {{ form_widget(form.cancel, {attr: {class: 'btn btn-danger'}}) }}
            </div>

            <div class="col-12 col-sm-6">
                {{ form_widget(form.submitPayment, {attr: {class: 'btn btn-success pull-right'}}) }}
            </div>
        </div>


        {{ form_end(form) }}

    {% else %}
        {{ messages.info('coreshop.ui.order_revise_payment_change_not_allowed') }}
    {% endif %}

{% endblock %}
