{% sw_extends '@Storefront/storefront/page/checkout/confirm/index.html.twig' %}

{% block base_header %}
    {% sw_include '@Storefront/storefront/page/account/order/header.html.twig' %}
{% endblock %}

{% set orderState = page.order.stateMachineState.technicalName %}

{% block page_checkout_confirm_header %}
    {% if page.errorCode == 'CHECKOUT__CUSTOMER_CANCELED_EXTERNAL_PAYMENT' %}
        {% sw_include '@Storefront/storefront/utilities/alert.html.twig' with {
            type: 'danger',
            content: 'account.externalPaymentCanceled'|trans|sw_sanitize
        } %}
    {% elseif page.errorCode == 'CHECKOUT__PAYMENT_TOKEN_EXPIRED' %}
        {% sw_include '@Storefront/storefront/utilities/alert.html.twig' with {
            type: 'danger',
            content: 'account.externalPaymentExpired'|trans|sw_sanitize
        } %}
    {% elseif page.errorCode is not null %}
        {% sw_include '@Storefront/storefront/utilities/alert.html.twig' with {
            type: 'danger',
            content: 'account.externalPaymentFailure'|trans|sw_sanitize
        } %}
    {% endif %}

    <h1 class="confirm-main-header">
        {{ "account.completePayment"|trans|sw_sanitize }}
    </h1>
{% endblock %}

{% block page_checkout_confirm_tos_control %}
    {{ "checkout.confirmTermsReminderText"|trans({
        '%url%': path('frontend.cms.page', { id: config('core.basicInformation.tosPage') })
    })|raw }}
{% endblock %}

{% block page_checkout_confirm_revocation_control %}
    {% set DOWNLOAD_STATE = constant('Shopware\\Core\\Content\\Product\\State::IS_DOWNLOAD') %}
    {% if page.order.lineItems.hasLineItemWithState(DOWNLOAD_STATE) %}
        <br>{{ "checkout.confirmRevocationReminder"|trans() }}
    {% endif %}
{% endblock %}

{% block page_checkout_confirm_address %}
    <div class="confirm-address">
        {% sw_include '@Storefront/storefront/page/account/order/address.html.twig' %}
    </div>
{% endblock %}

{% block page_checkout_confirm_payment %}
    <div class="col-sm-6 confirm-payment">
        {% sw_include '@Storefront/storefront/page/account/order/confirm-payment.html.twig' %}
    </div>
{% endblock %}

{% block page_checkout_confirm_shipping %}
    {% set PHYSICAL_STATE = constant('Shopware\\Core\\Content\\Product\\State::IS_PHYSICAL') %}
    {% if page.order.lineItems.hasLineItemWithState(PHYSICAL_STATE) %}
        <div class="col-sm-6 confirm-shipping">
            {% sw_include '@Storefront/storefront/page/account/order/confirm-shipping.html.twig' %}
        </div>
    {% endif %}
{% endblock %}

{% block page_checkout_confirm_table_header %}
    {% sw_include '@Storefront/storefront/component/checkout/cart-header.html.twig' with {
        showTaxPrice: true,
        showRemoveColumn: false
    } %}
{% endblock %}

{% block page_checkout_confirm_table_items %}
    {% for lineItem in page.order.nestedLineItems %}
        {% block page_checkout_confirm_table_item %}
            {% sw_include '@Storefront/storefront/component/line-item/line-item.html.twig' with {
                redirectTo: 'frontend.checkout.confirm.page',
                showTaxPrice: true,
                showRemoveButton: false
            } %}
        {% endblock %}
    {% endfor %}
{% endblock %}

{% block page_checkout_aside_actions %}
    <div class="checkout-aside-action">
        <form id="confirmOrderForm"
              action="{{ path('frontend.account.edit-order.update-order', { 'orderId': page.order.id }) }}"
              data-form-submit-loader="true"
              data-form-preserver="true"
              method="post">
            {% block page_checkout_aside_actions_payment_method_id %}
                <input type="hidden" name="paymentMethodId" value="{{ context.getPaymentMethod.getId }}">
            {% endblock %}

            {% set paymentMethodInvalid = true %}

            {% for payment in page.paymentMethods %}
                {% if payment.id is same as(context.paymentMethod.id) %}
                    {% set paymentMethodInvalid = false %}
                {% endif %}
            {% endfor %}

            {% block page_checkout_confirm_form_submit %}
                <button
                    class="btn btn-primary btn-block"
                    {% if page.paymentChangeable == false or paymentMethodInvalid == true %}
                        disabled="disabled"
                    {% endif %}
                    type="submit">
                    {{ "account.editOrderUpdateButton"|trans|sw_sanitize }}
                </button>
            {% endblock %}
        </form>

        {% block page_checkout_aside_cancel_order_modal_toggle %}
            {% if page.order.stateMachineState.technicalName != 'cancelled' and config('core.cart.enableOrderRefunds') %}
                <button type="button"
                        class="btn btn-light btn-block edit-order-cancel-order-modal-toggle-btn"
                        data-bs-toggle="modal"
                        data-bs-target="#cancelOrderModal">
                    {{ "account.editOrderCancelOrderButton"|trans|sw_sanitize }}
                </button>
            {% endif %}
        {% endblock %}

        {% if orderState != 'cancelled' %}
            {% sw_include '@Storefront/storefront/page/account/order/cancel-order-modal.html.twig' %}
        {% endif %}
    </div>
{% endblock %}

{% block base_footer %}
    {% sw_include '@Storefront/storefront/layout/footer/footer-minimal.html.twig' %}
{% endblock %}
