{extends file="widgets/base/widget.tpl"}

{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}

{strip}
    {block name="et-widget-container-inner"}
        <div class="row basket">
            {* Main Basket Area *}
            {block name='basket-index-main'}
                <div class="{block name='basket-index-main-class'}col col-12 col-lg-{if isset($Warenkorb->PositionenArr) && count($Warenkorb->PositionenArr) > 0}9{else}12{/if}{/block}">
                    {* Mobile Go-To Checkout Area *}
                    {block name='basket-index-goto-checkout'}
                        <div class="row et-basket-goto-checkout d-lg-none">
                            {block name='basket-index-goto-checkout-total'}
                                <div class="col-6 et-basket-goto-checkout-total">
                                    <span class="price_label">{lang key='totalSum' section='global'}:</span>
                                    <span class="total-sum">{$WarensummeLocalized[0]}</span>

                                    {if $Einstellungen.global.global_steuerpos_anzeigen !== 'N' && isset($Steuerpositionen) && count($Steuerpositionen) > 0}
                                        {foreach $Steuerpositionen as $Steuerposition}
                                            <span class="tax_label">{$Steuerposition->cName}</span>
                                        {/foreach}
                                    {/if}
                                </div>
                            {/block}

                            {block name='basket-index-goto-checkout-proceed'}
                                <div class="col-6 et-basket-goto-checkout-proceed">
                                    {include file="widgets/base/button.tpl" href="{get_static_route id='bestellvorgang.php'}?wk=1" variant="checkout" classes="btn-block" title="{lang key='nextStepCheckout' section='checkout'}" label="{lang key='nextStepCheckout' section='checkout'}"}
                                </div>
                            {/block}

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

                    {opcMountPoint id='opc_before_heading'}

                    {block name='basket-index-include-extension'}
                        {include file='snippets/extension.tpl'}
                    {/block}

                    {* Main Basket Area *}
                    {if isset($Warenkorb->PositionenArr) && count($Warenkorb->PositionenArr) > 0}
                        {block name='basket-index-basket'}
                            {opcMountPoint id='opc_before_basket'}
                            <div class="basket_wrapper">
                                {block name='basket-index-basket-items'}
                                    {* Form with all cart items and possible uploads *}
                                    {block name='basket-index-form-cart'}
                                        <form id="cart-form" method="post" action="{get_static_route id='warenkorb.php'}" class="jtl-validate label-slide">
                                            {csrf_token}
                                            <input type="hidden" name="wka" value="1" />
                                            {* The following hidden button prevents an iOS Safari Bug where the cart gets emptied when the user presses enter while changing quantities - see SHOP-7156 *}
                                            <button name="fake" tabindex="-1" class="btn-hidden-default" type="submit" style="height:0;width:0;margin:0;padding:0;border:0;display:block;overflow:visible;" aria-label="{lang key='addToCart'}"></button>
                                            {block name='basket-index-include-order-items-wrapper'}
                                                <div class="et-boxed-content">
                                                    {block name='basket-index-heading'}
                                                        <h1 class="h3 basket-heading">{lang key='basket'}{if !empty($cartProductCount)} ({$cartProductCount} {lang key='products'}){/if}</h1>
                                                    {/block}

                                                    <div class="basket-items">
                                                        {block name='basket-index-include-order-items'}
                                                            {include file='basket/cart_items.tpl'
                                                                lazyLoadImages=$et_BaseWidget.lazyLoadImages
                                                                additionalProductLink=$et_StandardBasket.additionalProductLink
                                                                additionalProductLinkAttribute=$et_StandardBasket.additionalProductLinkAttribute
                                                                additionalProductLinkLabel=$et_StandardBasket.additionalProductLinkLabel
                                                                characteristicsLimit=$et_StandardBasket.characteristicsLimit
                                                                characteristicValuesLimit=$et_StandardBasket.characteristicValuesLimit
                                                                showVatRatePerPosition=$et_StandardBasket.showVatRatePerPosition
                                                            }
                                                        {/block}
                                                    </div>
                                                </div>
                                            {/block}

                                            {block name='basket-index-include-uploads-wrapper'}
                                                {* This was moved into each cart_item per position -> see basket/cart_items.tpl *}
                                            {/block}
                                        </form>
                                    {/block}

                                    {* Coupon Form (if active and position should be below the cart items) *}
                                    {if $Einstellungen.kaufabwicklung.warenkorb_kupon_anzeigen === 'Y' && $KuponMoeglich == 1 && $et_StandardBasket.couponPosition === 'belowCartItems'}
                                        {block name='basket-index-coupon-below-items-wrapper'}
                                            <div class="et-boxed-content">
                                                {block name='basket-index-coupon-below-items'}
                                                    <div class="coupon-below-items">
                                                        {block name='basket-index-coupon-below-items-heading'}
                                                            <div class="h3 coupon-below-items-heading">{lang key='useCoupon' section='checkout'}</div>
                                                        {/block}
                                                        {if $shopIsAtLeast51}
                                                            {block name='checkout-coupon-form-desc'}
                                                                <p class="credit-description">{lang key='couponFormDesc' section='checkout'}</p>
                                                            {/block}
                                                        {/if}

                                                        <div id="coupon-form">
                                                            {block name='basket-index-coupon-below-items-form'}
                                                                <form class="jtl-validate label-slide  basket-coupon-form form-row" 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="col col-12 col-md-8 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}
                                                                    <div class="col col-12 col-md-4">
                                                                        {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}"}
                                                                    </div>
                                                                </form>
                                                            {/block}
                                                        </div>

                                                        {block name='basket-index-coupon-below-items-hr'}
                                                            {* <hr class="coupon-hr"> *}
                                                        {/block}
                                                    </div>
                                                {/block}
                                            </div>
                                        {/block}
                                    {/if}

                                    {if $shopIsAtLeast54}
                                        {block name='basket-index-include-free-hint'}
                                            {if $shopIsAtLeast54}
                                                {include file='basket/freegift_hint.tpl' cssClass="et-boxed-content" context="cart"}
                                            {/if}
                                        {/block}
                                    {/if}

                                    {* Calculate Shipping Costs *}
                                    {if $Einstellungen.kaufabwicklung.warenkorb_versandermittlung_anzeigen === 'Y'}
                                        {block name='basket-index-form-shipping-calc'}
                                            {opcMountPoint id='opc_before_shipping_calculator'}
                                            <form id="basket-shipping-estimate-form" class="shipping-calculator-form label-slide" method="post" action="{get_static_route id='warenkorb.php'}#basket-shipping-estimate-form" class="label-slide">
                                                {csrf_token}

                                                {block name='basket-index-include-shipping-calculator'}
                                                    <div class="et-boxed-content">
                                                        {include file='snippets/shipping_calculator.tpl' checkout=true hrAtEnd=false lazyLoadImages=$et_BaseWidget.lazyLoadImages}
                                                    </div>
                                                {/block}
                                            </form>
                                        {/block}
                                    {/if}

                                    {* Free Gifts *}
                                    {if $shopIsAtLeast54 && $freeGifts->count() > 0 || !$shopIsAtLeast54 && isset($oArtikelGeschenk_arr) && count($oArtikelGeschenk_arr) > 0}
                                        {$anyFreeGiftsDisplayable = true}
                                        {if $shopIsAtLeast54}
                                            {* Note: While $freeGifts->count may be positive, it may also be that the shop would not display any of them due to admin settings - we need to check this first *}
                                            {$anyFreeGiftsDisplayable = ($Einstellungen.sonstiges.sonstiges_gratisgeschenk_noch_nicht_verfuegbar_anzeigen === 'Y')}
                                            {if !$anyFreeGiftsDisplayable}
                                                {foreach $freeGifts as $item}
                                                    {if $item->getStillMissingAmount() <= 0}
                                                        {* Settings will hide all non-available gifts, but we have at least one available gift - we are good to go *}
                                                        {$anyFreeGiftsDisplayable = true}
                                                        {break}
                                                    {/if}
                                                {/foreach}
                                            {/if}
                                        {/if}

                                        {if $anyFreeGiftsDisplayable}
                                        {block name='basket-index-freegifts-content'}
                                            {$selectedFreegift=0}
                                            {foreach JTL\Session\Frontend::getCart()->PositionenArr as $oPosition}
                                                {if $oPosition->nPosTyp == $smarty.const.C_WARENKORBPOS_TYP_GRATISGESCHENK}
                                                    {$selectedFreegift=$oPosition->Artikel->kArtikel}
                                                {/if}
                                            {/foreach}

                                            <div class="et-boxed-content basket-freegift">
                                                {block name='basket-index-freegifts-heading'}
                                                    <div id="freeGiftsHeading" class="h2 basket-heading hr-sect">
                                                        {if !empty($oSpezialseiten_arr) && isset($oSpezialseiten_arr[$smarty.const.LINKTYP_GRATISGESCHENK])}
                                                            <a href="{$oSpezialseiten_arr[$smarty.const.LINKTYP_GRATISGESCHENK]->getURL()}"
                                                               title="{lang key='freeGiftFromOrderValueBasket'}">
                                                                {lang key='freeGiftFromOrderValueBasket'}
                                                            </a>
                                                        {else}
                                                            {lang key='freeGiftFromOrderValueBasket'}
                                                        {/if}
                                                    </div>
                                                {/block}

                                                <div class="col col-12 p-0">
                                                    {block name='basket-index-form-freegift'}
                                                        {assign var="sliderId" value=uniqid()}

                                                        <form method="post" name="freegift" action="{get_static_route id='warenkorb.php'}" class="label-slide">
                                                            {csrf_token}

                                                            {block name='basket-index-freegifts'}
                                                                <div class="slick-slider-other is-not-opc">
                                                                    {block name='basket-index-freegifts-slider'}
                                                                        <div class="et-slider slick-smooth-loading carousel slick-lazy{if $shopIsAtLeast54 && $freeGifts->count() < 3 || !$shopIsAtLeast54 && count($oArtikelGeschenk_arr) < 3} slider-no-preview{/if}"
                                                                            id="freegift"
                                                                            data-slick='{strip}{block name='basket-index-form-freegifts-slider-config'}{
                                                                                "nextArrow": "#et-freegift-slider-next-{$sliderId}",
                                                                                "prevArrow": "#et-freegift-slider-prev-{$sliderId}",
                                                                                "slidesToShow":   3,
                                                                                "slidesToScroll": 3,
                                                                                "infinite": false,
                                                                                "responsive": [
                                                                                    {
                                                                                        "breakpoint": 768,
                                                                                        "settings": {
                                                                                            "slidesToShow": 2,
                                                                                            "slidesToScroll": 2
                                                                                        }
                                                                                    }
                                                                                ]
                                                                            }{/block}{/strip}'
                                                                        >
                                                                            {if $shopIsAtLeast54}
                                                                                {include file='snippets/slider_items.tpl' items=$freeGifts type='freegift' lazyLoadImages=$et_BaseWidget.lazyLoadImages}
                                                                            {else}
                                                                                {include file='snippets/slider_items.tpl' items=$oArtikelGeschenk_arr type='freegift' lazyLoadImages=$et_BaseWidget.lazyLoadImages}
                                                                            {/if}
                                                                        </div>
                                                                    {/block}

                                                                    {* Freegift Slider Navigation *}
                                                                    {block name="basket-index-freegifts-slider-navigation-arrows"}
                                                                        <div class="et-slider-nav" id="et-freegift-slider-nav-{$sliderId}">
                                                                            {block name="basket-index-freegifts-slider-navigation-arrows-prev"}
                                                                                <div class="et-slider-nav-prev enabled slick-arrow slick-hidden" id="et-freegift-slider-prev-{$sliderId}">
                                                                                    <i class="{et_getIcon key='sliderPrevious'}"></i>
                                                                                </div>
                                                                            {/block}

                                                                            {block name="basket-index-freegifts-slider-navigation-arrows-next"}
                                                                                <div class="et-slider-nav-next enabled slick-arrow slick-hidden" id="et-freegift-slider-next-{$sliderId}">
                                                                                    <i class="{et_getIcon key='sliderNext'}"></i>
                                                                                </div>
                                                                            {/block}
                                                                        </div>
                                                                    {/block}
                                                                </div>
                                                            {/block}

                                                            {block name='basket-index-freegifts-form-submit'}
                                                                <input type="hidden" name="gratis_geschenk" value="1" />
                                                                <input name="gratishinzufuegen" type="hidden" value="{lang key='addToCart'}" />
                                                            {/block}
                                                        </form>
                                                    {/block}
                                                </div>
                                            </div>
                                        {/block}
                                        {/if}
                                    {/if}
                                {/block}

                                {* Cross Selling *}
                                {opcMountPoint id='opc_before_xselling'}
                                {if !empty($xselling->Kauf) && count($xselling->Kauf->Artikel) > 0}
                                    {block name='basket-index-basket-xsell'}
                                        {lang key='basketCustomerWhoBoughtXBoughtAlsoY' assign='panelTitle'}
                                        <div class="et-boxed-content">
                                            {block name='basket-index-include-product-slider'}
                                                {include file='snippets/product_slider.tpl' productlist=$xselling->Kauf->Artikel title=$panelTitle tplscope='half' lazyLoadImages=$et_BaseWidget.lazyLoadImages}
                                            {/block}
                                        </div>
                                    {/block}
                                {/if}
                                {opcMountPoint id='opc_after_xselling'}
                            </div>
                        {/block}
                    {* Empty Basket Area *}
                    {else}
                        {block name='basket-index-cart-empty'}
                            <div class="row basket-empty">
                                <div class="col">
                                    {block name='basket-index-alert-empty'}
                                        <div role="alert" class="alert alert-info">
                                            <span class="badge badge-light bubble">
                                                <i class="{et_getIcon key="basket"}"></i>
                                            </span><br/>
                                            {lang key='emptybasket' section='checkout'}
                                        </div>
                                    {/block}
                                    {block name='basket-index-empty-continue-shopping'}
                                        {include file="widgets/base/button.tpl" variant="primary" href="{if isset($ShopHomeURL)}{$ShopHomeURL}{else}{$ShopURL}{/if}" title="{lang key='continueShopping' section='checkout'}" label="{lang key='continueShopping' section='checkout'}"}
                                    {/block}
                                </div>
                            </div>
                        {/block}
                    {/if}
                </div>
            {/block}

            {* Basket Area Sidebar *}
            {if isset($Warenkorb->PositionenArr) && count($Warenkorb->PositionenArr) > 0}
                {block name='basket-index-side'}
                    <div class="{block name='basket-index-side-class'}col col-12 col-lg-3 ml-auto-util{/block}">
                        {include file="widgets/snippets/checkout_sidebar.tpl" couponPosition=$et_StandardBasket.couponPosition context='basket'}
                    </div>
                {/block}
            {/if}
        </div>
    {/block}
{/strip}