{block name='checkout-inc-shipping-address'}
    {assign var=fehlendeAngabenShipping value=$fehlendeAngaben.shippingAddress|default:null}
    {assign var=showShippingAddress value=(isset($Lieferadresse) || !empty($kLieferadresse) || isset($forceDeliveryAddress))}
    {et_isShopVersionAtLeast value="5.2.0-beta" assign='shopIsAtLeast52'}
    <div class="et-boxed-content">
        <div class="row inc-shipping-address">
            <div class="col col-12">
                {block name='checkout-inc-shipping-address-checkbox-equals'}
                    <div class="form-group checkbox control-toggle">
                        <input type="hidden" name="shipping_address" value="1" />
                        <div class="custom-control custom-checkbox custom-control-inline">
                            <input class="custom-control-input {if isset($forceDeliveryAddress)}d-none{/if}"
                                type="checkbox" id="checkout_register_shipping_address"
                                value="0"
                                name="shipping_address"
                                data-toggle="collapse"
                                data-target="#select_shipping_address"
                                {if !$showShippingAddress}checked{/if}
                            />
                            <label for="checkout_register_shipping_address" class="custom-control-label">
                                {lang key='shippingAdressEqualBillingAdress' section='account data'}
                            </label>
                        </div>
                    </div>
                {/block}
            </div>
            <div class="col col-12">
                {block name='checkout-inc-shipping-address-shipping-address'}
                <div id="select_shipping_address" class="select-shipping-address collapse collapse-non-validate{if $showShippingAddress} show{/if}">
                    {block name='checkout-inc-shipping-address-shipping-address-body'}
                        {if JTL\Session\Frontend::getCustomer()->getID() > 0 && isset($Lieferadressen) && count($Lieferadressen) > 0}
                            <div class="row">
                                <div class="col col-12">
                                    {block name='checkout-inc-shipping-address-legend-address'}
                                        <div class="h3">{lang key='deviatingDeliveryAddress' section='account data'}</div>
                                    {/block}
                                </div>
                                <div class="col col-12">
                                    {block name='checkout-inc-shipping-address-fieldset-address'}
                                        <fieldset>
                                            <ul class="list-group form-group exclude-from-label-slide">
                                            {$addressChecked = false}
                                            {foreach $Lieferadressen as $adresse}
                                                {if $shopIsAtLeast52}
                                                    {$checkAddress = (isset($shippingAddressPresetID) && ($shippingAddressPresetID == $adresse->kLieferadresse))
                                                                    || (!isset($shippingAddressPresetID) && (
                                                                            $kLieferadresse == $adresse->kLieferadresse
                                                                            || ($kLieferadresse != -1 && $kLieferadresse != $adresse->kLieferadresse && $adresse->nIstStandardLieferadresse == 1)))}
                                                {else}
                                                    {$checkAddress = false}
                                                {/if}
                                                {if $checkAddress}
                                                    {$addressChecked = true}
                                                {/if}
                                                {if $adresse->kLieferadresse > 0}
                                                    {block name='checkout-inc-shipping-address-address'}
                                                        <li class="list-group-item">
                                                            <label class="btn-block no-caret text-wrap mb-0" for="delivery{$adresse->kLieferadresse}" data-toggle="collapse" data-target="#register_shipping_address.show">
                                                                <div class="custom-control custom-radio custom-control-inline">
                                                                    <input
                                                                        class="custom-control-input"
                                                                        type="radio"
                                                                        id="delivery{$adresse->kLieferadresse}"
                                                                        name="kLieferadresse"
                                                                        value="{$adresse->kLieferadresse}"
                                                                        {if !$shopIsAtLeast52 && ($kLieferadresse == $adresse->kLieferadresse) || $checkAddress}checked{/if}
                                                                    >
                                                                    <label for="delivery{$adresse->kLieferadresse}" class="custom-control-label">
                                                                        <span class="control-label label-default">{if $adresse->cFirma}{$adresse->cFirma},{/if} {$adresse->cVorname} {$adresse->cNachname}, {$adresse->cStrasse} {$adresse->cHausnummer}, {$adresse->cPLZ} {$adresse->cOrt}, {$adresse->angezeigtesLand}</span>
                                                                    </label>
                                                                </div>
                                                            </label>
                                                            {if $shopIsAtLeast52}
                                                                <a href="{get_static_route id='jtl.php' params=['editLieferadresse' => 1, 'editAddress' => {$adresse->kLieferadresse}, 'fromCheckout'=>1]}" class="btn btn-link btn-sm" title="{lang key='editAddress' section='account data'}">
                                                                    <span class="{et_getIcon key="edit"}"></span>
                                                                </a>
                                                            {/if}
                                                        </li>
                                                    {/block}
                                                {/if}
                                            {/foreach}
                                            {block name='checkout-inc-shipping-address-new-address-wrapper'}
                                                {block name='checkout-inc-shipping-address-new-address'}
                                                    <li class="list-group-item">
                                                        {block name='checkout-inc-shipping-address-fieldset-new-address'}
                                                            <label class="btn-block" for="delivery_new" data-toggle="collapse" data-target="#register_shipping_address:not(.show)">
                                                                <div class="custom-control custom-radio custom-control-inline">
                                                                    <input
                                                                        class="custom-control-input"
                                                                        type="radio"
                                                                        id="delivery_new"
                                                                        name="kLieferadresse"
                                                                        value="-1"
                                                                        aria-controls="register_shipping_address"
                                                                        aria-expanded="{if !$addressChecked && ($kLieferadresse == -1)}true{else}false{/if}"
                                                                        {if !$addressChecked && ($kLieferadresse == -1)}checked{/if}
                                                                    >
                                                                    <label for="delivery_new" class="custom-control-label">
                                                                        <span class="control-label label-default">{lang key='createNewShippingAdress' section='account data'}</span>
                                                                    </label>
                                                                </div>
                                                            </label>
                                                        {/block}
                                                    </li>
                                                {/block}
                                            {/block}
                                            </ul>
                                        </fieldset>
                                    {/block}
                                    {block name='checkout-inc-shipping-address-fieldset-register'}
                                        <fieldset id="register_shipping_address" class="checkout-register-shipping-address collapse collapse-non-validate{if !$addressChecked && $kLieferadresse == -1} show{/if}">
                                            {block name='checkout-inc-shipping-address-legend-register'}
                                                <legend>{lang key='createNewShippingAdress' section='account data'}</legend>
                                            {/block}
                                            {block name='checkout-inc-shipping-address-include-customer-shipping-address'}
                                                {include file='checkout/customer_shipping_address.tpl' prefix="register" fehlendeAngaben=$fehlendeAngabenShipping}
                                            {/block}
                                            {block name='checkout-inc-shipping-address-include-customer-shipping-contact'}
                                                {include file='checkout/customer_shipping_contact.tpl' prefix="register" fehlendeAngaben=$fehlendeAngabenShipping}
                                            {/block}
                                        </fieldset>
                                    {/block}
                                </div>
                            </div>
                        {else}
                            <div class="row">
                                <div class="col col-12">
                                    {block name='checkout-inc-shipping-address-legend-register-first'}
                                        <div class="h3">{lang key='createNewShippingAdress' section='account data'}</div>
                                    {/block}
                                </div>
                                <div class="col col-12">
                                    {block name='checkout-inc-shipping-address-include-customer-shipping-address-first'}
                                        {include file='checkout/customer_shipping_address.tpl' prefix="register" fehlendeAngaben=$fehlendeAngabenShipping}
                                    {/block}
                                    {block name='checkout-inc-shipping-address-include-customer-shipping-contact-first'}
                                        {include file='checkout/customer_shipping_contact.tpl' prefix="register" fehlendeAngaben=$fehlendeAngabenShipping}
                                    {/block}
                                </div>
                            </div>
                        {/if}
                    {/block}
                </div>
                {/block}
            </div>
        </div>
        {if isset($smarty.get.editLieferadresse) || $step === 'Lieferadresse'}
            {block name='checkout-inc-shipping-address-script-show-shipping-address'}
                {inline_script}<script>
                    $(window).on('load', function () {
                        var $registerShippingAddress = $('#checkout_register_shipping_address');
                        if ($registerShippingAddress.prop('checked')) {
                            $registerShippingAddress.click();
                        }
                        $.evo.extended().smoothScrollToAnchor('#checkout_register_shipping_address');
                    });
                </script>{/inline_script}
            {/block}
        {/if}
    </div>
{/block}
