{block name='checkout-customer-shipping-address'}
    <fieldset>
    <div class="form-row customer-shipping-address">
        {et_isShopVersionAtLeast value="5.1.0" assign='shopIsAtLeast51'}
        {et_isShopVersionAtLeast value="5.2.0-beta" assign='shopIsAtLeast52'}
        {et_isShopVersionAtLeast value="5.3.0-rc.3" assign='shopIsAtLeast53'}
        {et_isShopVersionAtLeast value="5.4.0-rc.1" assign='shopIsAtLeast54'}
        {et_isShopVersionAtLeast value="5.5.0-rc.1" assign='shopIsAtLeast55'}
        {$name = 'shipping_address'}
        {* salutation / title *}
        {block name='checkout-customer-shipping-address-salutation-title'}
            {if $Einstellungen.kunden.lieferadresse_abfragen_anrede !== 'N'}
                <div class="col col-12 col-md-6">
                    {block name='checkout-customer-shipping-address-salutation'}
                        {formgroup
                            class="{if !empty($fehlendeAngaben.anrede)} has-error{/if}"
                            label="{lang key='salutation' section='account data'}{if $Einstellungen.kunden.lieferadresse_abfragen_anrede === 'O'}<span class='optional'> - {lang key='optional'}</span>{/if}"
                            label-for="{$prefix}-{$name}-salutation"
                        }
                            {if !empty($fehlendeAngaben.anrede)}
                                <div class="form-error-msg" aria-live="assertive" role="alert" aria-atomic="true">{lang key='fillOut'}</div>
                            {/if}
                            <select name="{$prefix}[{$name}][anrede]" id="{$prefix}-{$name}-salutation" class='form-control custom-select'{if $Einstellungen.kunden.lieferadresse_abfragen_anrede === 'Y'} required{/if} autocomplete="shipping sex" aria-invalid="{if !empty($fehlendeAngaben.anrede)}true{else}false{/if}">
                                <option value="" selected="selected" {if $Einstellungen.kunden.lieferadresse_abfragen_anrede === 'Y'}disabled{/if}>
                                    {if $Einstellungen.kunden.lieferadresse_abfragen_anrede === 'Y'}{lang key='salutation' section='account data'}{else}{lang key='noSalutation'}{/if}
                                </option>
                                <option value="w"{if isset($Lieferadresse->cAnrede) && $Lieferadresse->cAnrede === 'w'} selected="selected"{/if}>{lang key='salutationW'}</option>
                                <option value="m"{if isset($Lieferadresse->cAnrede) && $Lieferadresse->cAnrede === 'm'} selected="selected"{/if}>{lang key='salutationM'}</option>
                            </select>
                        {/formgroup}
                    {/block}
                </div>
            {/if}
            {if $Einstellungen.kunden.lieferadresse_abfragen_titel !== 'N'}
                <div class="col col-12 col-md-6">
                    {block name='checkout-customer-shipping-address-title-prefix'}
                        {include file='snippets/form_group_simple.tpl'
                            options=[
                                "text", "{$prefix}-{$name}-title", "{$prefix}[{$name}][titel]",
                                {$Lieferadresse->cTitel|default:null},
                                {lang key='title' section='account data'}, {$Einstellungen.kunden.lieferadresse_abfragen_titel},
                                null, "shipping honorific-prefix", null, 64
                            ]
                        }
                    {/block}
                </div>
            {/if}
            <div class="w-100-util"></div>
        {/block}

        {* firstname lastname *}
        {block name='checkout-customer-shipping-address-firstname-lastname'}
            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-first-name'}
                    {include file='snippets/form_group_simple.tpl'
                        options=[
                            "text", "{$prefix}-{$name}-firstName", "{$prefix}[{$name}][vorname]",
                            {$Lieferadresse->cVorname|default:null}, {lang key='firstName' section='account data'},
                            {$Einstellungen.kunden.kundenregistrierung_pflicht_vorname},
                            null, "shipping given-name"
                        ]
                    }
                {/block}
            </div>
            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-last-name'}
                    {include file='snippets/form_group_simple.tpl'
                        options=[
                            "text", "{$prefix}-{$name}-lastName", "{$prefix}[{$name}][nachname]",
                            {$Lieferadresse->cNachname|default:null}, {lang key='lastName' section='account data'},
                            true, null, "shipping family-name"
                        ]
                    }
                {/block}
            </div>
            <div class="w-100-util"></div>
        {/block}

        {* firm / firmtext *}
        {block name='checkout-customer-shipping-address-company-wrap'}
            {$askForCompany = $Einstellungen.kunden.kundenregistrierung_abfragen_firma}
            {$askForCompanyAdditional = $Einstellungen.kunden.kundenregistrierung_abfragen_firmazusatz}
            {if $shopIsAtLeast51}
                {$askForCompany = $Einstellungen.kunden.lieferadresse_abfragen_firma}
                {$askForCompanyAdditional = $Einstellungen.kunden.lieferadresse_abfragen_firmazusatz}
            {/if}
            {if $askForCompany !== 'N' || $askForCompanyAdditional !== 'N'}
                {if isset($companyOpenByDefault) && !$companyOpenByDefault && $askForCompany !== 'Y' && $askForCompanyAdditional !== 'Y'}
                    {block name='checkout-customer-shipping-address-company-trigger'}
                        <div class="col col-12">
                            <a href="#" class="link-discreet et-checkout-firm-trigger" title="{et_language key='et360_add_company_data'}" onclick="$('#shipping-address-firm-input').show();$(this).hide();return false;">
                                <i class="{et_getIcon key="addCompany"}"></i>&nbsp;{et_language key='et360_add_company_data'}
                            </a>
                        </div>
                    {/block}
                {/if}

                <div class="col col-12" {if isset($companyOpenByDefault) && !$companyOpenByDefault && $askForCompany !== 'Y' && $askForCompanyAdditional !== 'Y'} style="display:none;"{/if} id="shipping-address-firm-input">
                    <div class="form-row">
                        {if $askForCompany !== 'N'}
                            <div class="col col-12 col-md-6">
                                {block name='checkout-customer-shipping-address-company'}
                                    {include file='snippets/form_group_simple.tpl'
                                        options=[
                                            "text", "{$prefix}-{$name}-firm", "{$prefix}[{$name}][firma]",
                                            {$Lieferadresse->cFirma|default:null}, {lang key='firm' section='account data'},
                                            $askForCompany, null, "shipping organization",
                                            null, 128
                                        ]
                                    }
                                {/block}
                            </div>
                        {/if}
                        {if $askForCompanyAdditional !== 'N'}
                            <div class="col col-12 col-md-6">
                                {block name='checkout-customer-shipping-address-company-additional'}
                                    {include file='snippets/form_group_simple.tpl'
                                        options=[
                                            "text", "{$prefix}-{$name}-firmext", "{$prefix}[{$name}][firmazusatz]",
                                            {$Lieferadresse->cZusatz|default:null}, {lang key='firmext' section='account data'},
                                            $askForCompanyAdditional, null, "shipping organization ext", null, 60
                                        ]
                                    }
                                {/block}
                            </div>
                        {/if}
                    </div>
                </div>

                <div class="w-100-util"></div>
            {/if}
        {/block}

        {* street / number *}
        {block name='checkout-customer-shipping-address-street-wrap'}
            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-street'}
                    {include file='snippets/form_group_simple.tpl'
                        options=[
                            "text", "{$prefix}-{$name}-street", "{$prefix}[{$name}][strasse]",
                            {$Lieferadresse->cStrasse|default:null}, {lang key='street' section='account data'},
                            true, null, "shipping address-line1"
                        ]
                    }
                {/block}
            </div>
            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-street-number'}
                    {include file='snippets/form_group_simple.tpl'
                        options=[
                            "text", "{$prefix}-{$name}-streetnumber", "{$prefix}[{$name}][hausnummer]",
                            {$Lieferadresse->cHausnummer|default:null}, {lang key='streetnumber' section='account data'},
                            true, null, "shipping address-line2"
                        ]
                    }
                {/block}
            </div>
            <div class="w-100-util"></div>
        {/block}

        {* address addition *}
        {if $Einstellungen.kunden.lieferadresse_abfragen_adresszusatz !== 'N'}
            {block name='checkout-customer-shipping-address-addition'}
                <div class="col col-12 col-md-6">
                    {block name='checkout-customer-shipping-address-street-additional'}
                        {include file='snippets/form_group_simple.tpl'
                            options=[
                                "text", "{$prefix}-{$name}-street2", "{$prefix}[{$name}][adresszusatz]",
                                {$Lieferadresse->cAdressZusatz|default:null}, {lang key='street2' section='account data'},
                                $Einstellungen.kunden.lieferadresse_abfragen_adresszusatz, null, "shipping address-line3"
                            ]
                        }
                    {/block}
                </div>
            {/block}
            <div class="w-100-util"></div>
        {/if}

        {* zip / city *}
        {block name='checkout-customer-shipping-address-city-wrap'}
            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-zip'}
                    {formgroup
                        class="{if !empty($fehlendeAngaben.plz)} has-error{/if} postcode-wrapper{if $shopIsAtLeast55} typeahead-required{/if}"
                        label="{lang key='plz' section='account data'}"
                        label-for="{$prefix}-{$name}-postcode"
                    }
                        {if isset($fehlendeAngaben.plz)}
                            <div class="form-error-msg" aria-live="assertive" role="alert" aria-atomic="true"><i class="{et_getIcon key="missingInput"}"></i>
                                {if $fehlendeAngaben.plz >= 2}
                                    {lang key='checkPLZCity' section='checkout'}
                                {else}
                                    {lang key='fillOut'}
                                {/if}
                            </div>
                        {/if}
                        <input
                            type="text"
                            name="{$prefix}[{$name}][plz]"
                            value="{if isset($Lieferadresse->cPLZ)}{$Lieferadresse->cPLZ}{/if}"
                            id="{$prefix}-{$name}-postcode"
                            class="form-control postcode_input{if $shopIsAtLeast55} typeahead bg-typeahead-fix{/if}"
                            placeholder=" "
                            data-toggle="postcode"
                            data-city="#{$prefix}-{$name}-city"
                            data-country="#{$prefix}-{$name}-country"
                            {if $shopIsAtLeast53}data-chars-left-msg="{lang key='charactersLeft'}"{/if}
                            required
                            autocomplete="shipping postal-code"
                            maxlength="20"
                            aria-invalid="{if isset($fehlendeAngaben.plz)}true{else}false{/if}"
                        />
                    {/formgroup}
                {/block}
            </div>

            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-city'}
                    {formgroup
                        class="{if !empty($fehlendeAngaben.ort)} has-error{/if} city-wrapper{if $shopIsAtLeast55} typeahead-required{else} exclude-from-label-slide{/if}"
                        label="{if $shopIsAtLeast55}{lang key='city' section='account data'}{/if}"
                        label-for="{$prefix}-{$name}-city"
                    }
                        {if isset($fehlendeAngaben.ort)}
                            <div class="form-error-msg" aria-live="assertive" role="alert" aria-atomic="true"><i class="{et_getIcon key="missingInput"}"></i>
                                {if !$shopIsAtLeast54 && $fehlendeAngaben.ort==3}
                                    {* The non-numeric city error was removed in 5.4.0 *}
                                    {lang key='cityNotNumeric' section='account data'}
                                {else}
                                    {lang key='fillOut' section='global'}
                                {/if}
                            </div>
                        {/if}
                        <input type="text"
                            name="{$prefix}[{$name}][ort]"
                            value="{if isset($Lieferadresse->cOrt)}{$Lieferadresse->cOrt}{/if}"
                            id="{$prefix}-{$name}-city"
                            class="form-control city_input typeahead bg-typeahead-fix"
                            placeholder="{if $shopIsAtLeast55} {else}{lang key='city' section='account data'}{/if}"
                            required
                            autocomplete="shipping address-level2"
                            aria-label="{lang key='city' section='account data'}"
                            aria-invalid="{if isset($fehlendeAngaben.ort)}true{else}false{/if}"
                        />
                    {/formgroup}
                {/block}
            </div>
        {/block}

        {* country *}
        {if isset($Lieferadresse->cLand)}
            {$countryISO=$Lieferadresse->cLand}
        {elseif !empty($smarty.session.preferredDeliveryCountryCode)}
            {$countryISO=$smarty.session.preferredDeliveryCountryCode}
        {elseif !empty($Kunde->cLand)}
            {$countryISO=$Kunde->cLand}
        {elseif !empty($Einstellungen.kunden.lieferadresse_abfragen_standardland)}
            {$countryISO=$Einstellungen.kunden.lieferadresse_abfragen_standardland}
        {else}
            {$countryISO=$shippingCountry}
        {/if}
        {getCountry iso=$countryISO assign='selectedCountry'}
        {block name='checkout-customer-shipping-address-country-wrap'}
            <div class="col col-12 col-md-6">
                {block name='checkout-customer-shipping-address-country'}
                    {formgroup label="{lang key='country' section='account data'}" label-for="{$prefix}-{$name}-country"}
                        <select name="{$prefix}[{$name}][land]" id="{$prefix}-{$name}-country" class="form-control country-input custom-select js-country-select" autocomplete="shipping country">
                            <option value="" selected disabled>{lang key='country' section='account data'}</option>
                            {foreach $LieferLaender as $land}
                               {if !$shopIsAtLeast51 || $land->isShippingAvailable()}
                                    <option value="{$land->getISO()}" {if $countryISO === $land->getISO()}selected="selected"{/if}>{$land->getName()}</option>
                               {/if}
                            {/foreach}
                        </select>
                    {/formgroup}
                {/block}
            </div>
            {if $Einstellungen.kunden.lieferadresse_abfragen_bundesland !== 'N'}
                {getStates cIso=$countryISO assign='oShippingStates'}
                {if isset($Lieferadresse->cBundesland)}
                    {assign var=cState value=$Lieferadresse->cBundesland}
                {elseif !empty($Kunde->cBundesland)}
                    {assign var=cState value=$Kunde->cBundesland}
                {else}
                    {assign var=cState value=''}
                {/if}
                <div class="col col-12 col-md-6">
                    {block name='checkout-customer-shipping-address-state'}
                        {formgroup
                            class="{if isset($fehlendeAngaben.bundesland)} has-error{/if}"
                            label="{lang key='state' section='account data'}{if $Einstellungen.kunden.lieferadresse_abfragen_bundesland !== 'Y'}<span class='optional'> - {lang key='optional'}</span>{/if}"
                            label="{lang key='state' section='account data'}<span class='state-optional optional {if $Einstellungen.kunden.lieferadresse_abfragen_bundesland === 'Y' || ($shopIsAtLeast51 && $selectedCountry->isRequireStateDefinition())}d-none{/if}'> - {lang key='optional'}</span>"
                            label-for="{$prefix}-{$name}-state"
                        }
                            {if !empty($oShippingStates)}
                                <select
                                        name="{$prefix}[{$name}][bundesland]"
                                        id="{$prefix}-{$name}-state"
                                        class="form-control state-input custom-select js-state-select"
                                        data-defaultoption="{lang key=pleaseChoose}"
                                        autocomplete="shipping address-level1"
                                        aria-invalid="{if !empty($fehlendeAngaben.bundesland)}true{else}false{/if}"
                                        {if $Einstellungen.kunden.lieferadresse_abfragen_bundesland === 'Y' || ($shopIsAtLeast51 && $selectedCountry->isRequireStateDefinition())}required{/if}"
                                >
                                    <option value="" selected disabled>{lang key='pleaseChoose'}</option>
                                    {foreach $oShippingStates as $oState}
                                        <option value="{$oState->cCode}" {if $cState === $oState->cName || $cState === $oState->cCode}selected{/if}>{$oState->cName}</option>
                                    {/foreach}
                                </select>
                            {else}
                                <input
                                    class="form-control"
                                    type="text"
                                    name="{$prefix}[{$name}][bundesland]"
                                    value="{if isset($Lieferadresse->cBundesland)}{$Lieferadresse->cBundesland}{/if}"
                                    id="{$prefix}-{$name}-state"
                                    data-toggle="state"
                                    data-defaultoption="{lang key=pleaseChoose}"
                                    data-target="#{$prefix}-{$name}-country"
                                    placeholder="{lang key='state' section='account data'}"
                                    {if $Einstellungen.kunden.lieferadresse_abfragen_bundesland === 'Y'}required{/if}
                                    autocomplete="shipping address-level1"
                                    aria-invalid="{if !empty($fehlendeAngaben.bundesland)}true{else}false{/if}"
                                />
                            {/if}

                            {if !empty($fehlendeAngaben.bundesland)}
                                <div class="form-error-msg" aria-live="assertive" role="alert" aria-atomic="true">{lang key='fillOut'}</div>
                            {/if}
                        {/formgroup}
                    {/block}
                </div>
            {/if}
            {block name='checkout-customer-shipping-address-is-default-wrap'}
                {if $shopIsAtLeast55}
                    {if !empty($Kunde->kKunde) && $Kunde->isLoggedIn()}
                        <div class="w-100-util"></div>
                        <div class="col-12">
                            {block name='checkout-customer-shipping-address-is-default'}
                                <div class="custom-control custom-checkbox custom-control-inline">
                                    <input type="checkbox" class="custom-control-input" id="checkout_register_set-shipping-address-as-default" name="{$prefix}[{$name}][isDefault]" value="1"
                                        {if isset($Lieferadresse->nIstStandardLieferadresse) && $Lieferadresse->nIstStandardLieferadresse === 1} checked="checked"{/if} />
                                   <label for="checkout_register_set-shipping-address-as-default" class="custom-control-label">{lang key='checkoutSaveShippingAddressAsDefault' section='account data'}</label>
                                </div>
                            {/block}
                        </div>
                    {/if}
                {/if}
            {/block}
            {block name='checkout-customer-shipping-address-save-preset-wrap'}
                {if $shopIsAtLeast52}
                    {if $step == 'Lieferadresse' || $step == 'edit_customer_address'}
                        <div class="w-100-util"></div>
                        <div class="col-12">
                            {block name='checkout-customer-shipping-address-save-preset'}
                                <div class="custom-control custom-checkbox custom-control-inline">
                                    <input type="checkbox" class="custom-control-input" id="checkout_register_save-shipping-address-as-preset" name="{$prefix}[{$name}][saveAsNewShippingAddressPreset]" value="1"/>
                                    <label for="checkout_register_save-shipping-address-as-preset" class="custom-control-label">{lang key='checkoutSaveAsNewShippingAddressPreset' section='account data'}</label>
                                </div>
                            {/block}
                        </div>
                    {/if}
                {/if}
            {/block}
        {/block}
    </div>
    </fieldset>
{/block}
