{block name='standard-checkout-sidebar-snippet'}
    {assign var="couponPosition" value=$couponPosition|default:'none'}
    {assign var="context" value=$context|default:false}
    {$agbWrbCheckboxPosition=$agbWrbCheckboxPosition|default:'default'}
    {et_isShopVersionAtLeast value="5.1.0" assign='shopIsAtLeast51'}
    {et_isShopVersionAtLeast value="5.4.0-rc.1" assign='shopIsAtLeast54'}
    {if $shopIsAtLeast54}
        {* Since 5.4.0, the Smarty variable has been renamed (although the old name still exists, it is assigned deprecatedly) *}
        {$cartProductCount = $WarenkorbArtikelAnzahl}
    {else}
        {$cartProductCount = $WarenkorbArtikelPositionenanzahl}
    {/if}

    <div class="et-sticky et-sticky-affix cart-summary"
         data-affix-to="parent"
         data-sticky-breakpoints='{strip}{block name='et-checkout-sidebar-sticky-breakpoints'}
            {
                "xs": false, "sm": false, "md": false, "lg": true, "xl": true
            }
        {/block}{/strip}'>
        {* Basket Side Heading (not used by default) *}
        {block name='standard-checkout-sidebar-heading'}
            {* <div class="h2 basket-heading">{lang key="orderOverview" section="account data"}</div> *}
        {/block}

        {* Sidebar Summary *}
        {block name='standard-checkout-sidebar-summary'}
            <div class="et-boxed-content basket-summary">
                {* Product Count *}
                {block name='standard-checkout-sidebar-product-count'}
                    <div class="row et-basket-sidebar-products">
                        <div class="col col-7 text-left-util">{lang key="products" section="global"}:</div>
                        <div class="col col-5 text-right-util">{$cartProductCount}</div>
                    </div>
                {/block}

                {* Show Tax and Pricing *}
                {block name='standard-checkout-sidebar-price-tax'}
                    {* Pricing *}
                    {block name='standard-checkout-sidebar-price-sticky'}
                        <div class="row basket-summary-total">
                            <div class="col col-7 text-left-util">
                                <span class="price_label">{lang key='subtotal' section='global'}:</span>
                            </div>
                            <div class="col col-5 text-right-util price-col">
                                <strong class="total-sum">{$WarensummeLocalized[0]}</strong>
                            </div>
                        </div>
                    {/block}

                    {* Show Net Price *}
                    {if $NettoPreise}
                        {block name='standard-checkout-sidebar-price-net'}
                            <div class="row total-net">
                                <div class="col col-7 text-left-util">
                                    <span class="price_label"><strong>{lang key='subtotal' section='global'} ({lang key='net'}):</strong></span>
                                </div>
                                <div class="col col-5 text-right-util price-col">
                                    <strong class="price total-sum">{$WarensummeLocalized[$NettoPreise]}</strong>
                                </div>
                            </div>
                        {/block}
                    {/if}

                    {* Show tax positions *}
                    {if $Einstellungen.global.global_steuerpos_anzeigen !== 'N' && isset($Steuerpositionen) && count($Steuerpositionen) > 0}
                        {block name='standard-checkout-sidebar-tax'}
                            {foreach $Steuerpositionen as $Steuerposition}
                                <div class="row tax">
                                    <div class="col col-7 text-left-util">
                                        <span class="tax_label">{$Steuerposition->cName}:</span>
                                    </div>
                                    <div class="col col-5 text-right-util price-col">
                                        <span class="tax_label">{$Steuerposition->cPreisLocalized}</span>
                                    </div>
                                </div>
                            {/foreach}
                        {/block}
                    {/if}

                    {* Show used user credit *}
                    {if isset($smarty.session.Bestellung->GuthabenNutzen) && $smarty.session.Bestellung->GuthabenNutzen == 1}
                        {block name='standard-checkout-sidebar-credit'}
                            <div class="row customer-credit">
                                <div class="col col-7 text-left-util">
                                    {lang key='useCredit' section='account data'}
                                </div>
                                <div class="col col-5 text-right-util">
                                    {$smarty.session.Bestellung->GutscheinLocalized}
                                </div>
                            </div>
                        {/block}
                    {/if}
                {/block}

                {* Shipping Cost *}
                {block name='standard-checkout-sidebar-shipping'}
                    {if $context == 'basket' && $favourableShippingString !== ''}
                        <div class="row shipping-costs">
                            <div class="col col-12">
                                <small>{$favourableShippingString}</small>
                            </div>
                        </div>
                    {/if}
                {/block}

                {* Proceed to checkout *}
                {if $context && $context !== 'checkout_step5'}
                    {block name='standard-checkout-sidebar-proceed-button'}
                        {if $context !== 'basket'}
                            {* Note: on step0 this button works like 'login' iff a password is set and no last name was entered - else it works like a 'continue as new customer' *}
                            {* Also note: this button only delegates clicks to the actual form buttons, hidden or not *}
                            {include file="widgets/base/button.tpl" variant="checkout" classes="btn-block" id="cart-checkout-btn" type="button" label="{et_language key='et360_checkout_continue'}"}
                        {else}
                            {include file="widgets/base/button.tpl" variant="checkout" classes="btn-block" id="cart-checkout-btn" href="{get_static_route id='bestellvorgang.php'}?wk=1" title="{lang key='nextStepCheckout' section='checkout'}" label="{lang key='nextStepCheckout' section='checkout'}"}
                        {/if}
                    {/block}
                {/if}

                {if $context === 'basket'}
                    {block name='standard-checkout-sidebar-payment-method-buttons'}
                        <div class="et-cart-payment-method-buttons">
                            <div id="amapay-basket" class="amapay-basket"></div>
                        </div>
                    {/block}
                {/if}

                {* Checkout Confirmation Form *}
                {if $context === 'checkout_step5'}
                    {block name='standard-checkout-sidebar-include-confirmation-form'}
                        <div class="order-submit">
                            {include file="widgets/snippets/checkout_sidebar_confirmation_form.tpl" agbWrbCheckboxPosition=$agbWrbCheckboxPosition}
                        </div>
                    {/block}
                {/if}

                {* Estimated delivery *}
                {block name='standard-checkout-sidebar-estimated-delivery'}
                    {if isset($smarty.session.Warenkorb)}
                        {$cEstimatedDelivery = $smarty.session.Warenkorb->getEstimatedDeliveryTime()}
                        {if $cEstimatedDelivery|@count_characters > 0}
                            <div class="row et-basket-sidebar-delivery">
                                <div class="col col-12">
                                    <i class="{et_getIcon key='shipping'} status-icon"></i> {lang key="shippingTime" section="global"} {$cEstimatedDelivery}
                                </div>
                            </div>
                        {/if}
                    {/if}
                {/block}

                {* Block to easily add additional Text *}
                {block name='standard-checkout-sidebar-additional-text'}{/block}

                {* Coupon if active and it should be in the sidebar *}
                {if $Einstellungen.kaufabwicklung.warenkorb_kupon_anzeigen === 'Y' && isset($KuponMoeglich) && $KuponMoeglich == 1 && $couponPosition === 'inAffix'}
                    {block name='standard-checkout-sidebar-coupon'}
                        {block name='standard-checkout-sidebar-coupon-heading'}
                            {* Not used by easytemplate *}
                        {/block}

                        <div id="coupon-form">
                            {block name='standard-checkout-sidebar-coupon-form'}
                                <form class="jtl-validate label-slide basket-coupon-form" id="basket-coupon-form" method="post" action="{get_static_route id='warenkorb.php'}">
                                    {csrf_token}
                                    {formgroup label-for="couponCode" label="{if $shopIsAtLeast51}{lang key='couponCodePlaceholder' section='checkout'}{else}{lang key='couponCode' section='account data'}{/if}" class="mw-100{if !empty($invalidCouponCode)} has-error{/if}"}
                                        <input aria-label="{if $shopIsAtLeast51}{lang key='couponCodePlaceholder' section='checkout'}{else}{lang key='couponCode' section='account data'}{/if}" type="text" name="Kuponcode" id="couponCode" maxlength="32" placeholder=" " required class="form-control" />
                                    {/formgroup}
                                    {include file="widgets/base/button.tpl" type="submit" value="1" variant="secondary" classes="btn-block" label="{if $shopIsAtLeast51}{lang key='couponSubmit' section='checkout'}{else}{lang key='useCoupon' section='checkout'}{/if}"}
                                </form>
                            {/block}
                        </div>
                    {/block}
                {/if}

                {* Step 5: Confirmation - Payment Options *}
                {if $context === 'checkout_step5'}
                    {* Coupon *}
                    {if isset($KuponMoeglich) && $KuponMoeglich}
                        {block name='checkout-step5-confirmation-coupon'}
                            <div id="panel-edit-coupon">
                                {if isset($couponOpenByDefault) && !$couponOpenByDefault && empty($Kuponcode)}
                                    {block name='checkout-step5-confirmation-coupon-trigger'}
                                        <div class="row">
                                            <div class="col col-12">
                                                <a href="#" class="link-discreet et-checkout-coupon-trigger" title="{if $shopIsAtLeast51}{lang key='couponCodePlaceholder' section='checkout'}{else}{lang key='couponCode' section='account data'}{/if}" onclick="$('.et-checkout-coupon-trigger-target').show();$(this).hide();return false;">
                                                    <i class="{et_getIcon key="edit"} et-icon-fw"></i> {if $shopIsAtLeast51}{lang key='couponCodePlaceholder' section='checkout'}{else}{lang key='couponCode' section='account data'}{/if}
                                                </a>
                                            </div>
                                        </div>
                                    {/block}
                                {/if}
                                {block name='checkout-step5-confirmation-coupon-trigger-target'}
                                    <div class="et-checkout-coupon-trigger-target"{if isset($couponOpenByDefault) && !$couponOpenByDefault && empty($Kuponcode)} style="display:none;"{/if}>
                                        {block name='checkout-step5-confirmation-coupon-header'}
                                            {* <div class="h3 checkout-confirmation-heading">{lang key='coupon' section='account data'}</div> *}
                                        {/block}

                                        {block name='checkout-step5-confirmation-include-coupon-form'}
                                            {include file='checkout/coupon_form.tpl' couponPosition='inAffix'}
                                        {/block}
                                    </div>
                                {/block}
                            </div>
                        {/block}
                    {/if}

                    {* User Credit *}
                    {if isset($GuthabenMoeglich) && $GuthabenMoeglich}
                        {block name='checkout-step5-confirmation-credit'}
                            <div id="panel-edit-credit">
                                {block name='checkout-step5-confirmation-credit-header'}
                                    {* <div class="h3 checkout-confirmation-heading">{lang key='credit' section='account data'}</div> *}
                                {/block}

                                {block name='checkout-step5-confirmation-include-credit-form'}
                                    {include file='checkout/credit_form.tpl'}
                                {/block}
                            </div>
                        {/block}
                    {/if}
                {/if}
            </div>
        {/block}

        {* Shipping notes *}
        {if !empty($WarenkorbVersandkostenfreiHinweis) && isset($smarty.session.Warenkorb) && isset($smarty.session.Warenkorb->PositionenArr) && count($smarty.session.Warenkorb->PositionenArr) > 0}
            {block name='standard-checkout-sidebar-alert'}
                <div class="et-boxed-content basket-summary-notice">
                    <div class="row no-gutters">
                        <div class="col col-auto"><i class="{et_getIcon key="info"} status-icon"></i></div>
                        <div class="col basket_notice">{$WarenkorbVersandkostenfreiHinweis}</div>
                    </div>
                </div>
            {/block}
        {/if}
        {* Cart weight *}
        {if isset($Einstellungen.kaufabwicklung.warenkorb_gesamtgewicht_anzeigen) && $Einstellungen.kaufabwicklung.warenkorb_gesamtgewicht_anzeigen === 'Y'}
            {block name='basket-index-notice-weight'}
                <div class="et-boxed-content basket-summary-notice-weight-wrapper">
                    <div class="row no-gutters">
                        <div class="col col-auto"><i class="{et_getIcon key="weight"} status-icon"></i></div>
                        <div class="col basket_notice basket-summary-notice-weight">{lang key='cartTotalWeight' section='basket' printf=$WarenkorbGesamtgewicht}</div>
                    </div>
                </div>
            {/block}
        {/if}
    </div>

    {* Scripts to manipulate the behaviour of the proceed button depending on which step we are in *}
    {block name='standard-checkout-sidebar-scripts'}
        {if $context}
            {inline_script}<script>
                $('#cart-checkout-btn').on('click', function(e) {
                    {if $context === 'checkout_step0'}
                        if( $('#order_register_or_login [name="passwort"]').val() !== '' && $('#form-register [name="nachname"]').val() === '') {
                            $('#order_register_or_login [type="submit"]').trigger('click');
                        } else {
                            $('#form-register [type="submit"]').first().trigger('click');
                        }
                    {elseif $context === 'checkout_step1'}
                        $('#neukunde [type="submit"]').first().trigger('click');
                    {elseif $context === 'checkout_step3'}
                        if ($('#ppp-submit').length) {
                            $('#ppp-submit').trigger('click');
                        } else {
                            $('.checkout-shipping-form [type="submit"]').first().trigger('click');
                        }
                    {/if}
                });
            </script>{/inline_script}
        {/if}
    {/block}
{/block}