{block name='account-shipping-address-form'}
    {et_isShopVersionAtLeast value="5.5.0-rc.1" assign='shopIsAtLeast55'}
    {block name='account-shipping-address-form-form'}
        {$isModal = $isModal|default:false}
        <div class="row">
            <div class="{block name='account-shipping-address-form-form-wrapper-classes'}col-12{if !$isModal} col-md-6{/if} shipping-address-form-wrapper{/block}">
            {block name='account-shipping-address-form-form-wrapper'}
                <form method="post" id='lieferadressen' action="{get_static_route params=['editLieferadresse' => 1]}" class="jtl-validate label-slide">
                    {csrf_token}
                    {block name='et-account-shipping-address-form-required-info'}
                        {if $shopIsAtLeast55}
                            <div class="required-info">{lang key='requiredInfo'}</div>
                        {/if}
                    {/block}
                    {block name='account-shipping-address-form-include-customer-shipping-address'}
                        {include file='checkout/customer_shipping_address.tpl' prefix="register" fehlendeAngaben=null}
                    {/block}
                    {block name='account-shipping-address-form-include-customer-shipping-contact'}
                        {include file='checkout/customer_shipping_contact.tpl' prefix="register" fehlendeAngaben=null}
                    {/block}
                    {block name='account-shipping-address-form-form-submit'}
                        <div class="row btn-row">
                            <div class="col-12 col-md-12 col-xl-6 checkout-button-row-new-address">
                                {if isset($Lieferadresse->kLieferadresse) && !isset($smarty.get.fromCheckout)}
                                    <a class="btn btn-secondary btn-block" href="{get_static_route id='jtl.php' params=['editLieferadresse' => 1]}">
                                        <i class="{et_getIcon key="navigationPrevious"}"></i>&nbsp;{lang key='newShippingAddress' section='account data'}
                                    </a>
                                {/if}
                            </div>
                            <div class="col-12 col-md-12 col-xl-6 checkout-button-row-submit mb-3">
                                <input type="hidden" name="editLieferadresse" value="1">
                                {if isset($Lieferadresse->nIstStandardLieferadresse) && $Lieferadresse->nIstStandardLieferadresse === 1}
                                    <input type="hidden" name="isDefault" value=1>
                                {/if}
                                {if isset($Lieferadresse->kLieferadresse) && !isset($smarty.get.fromCheckout)}
                                    <input type="hidden" name="updateAddress" value="{$Lieferadresse->kLieferadresse}">
                                    <button type="submit" value="1" class="btn btn-primary btn-block">
                                        {lang key='updateAddress' section='account data'}
                                    </button>
                                {elseif !isset($Lieferadresse->kLieferadresse)}
                                    <input type="hidden" name="editAddress" value="neu">
                                    <button type="submit" value="1" class="btn btn-primary btn-block">
                                        {lang key='saveAddress' section='account data'}
                                    </button>
                                {elseif isset($Lieferadresse->kLieferadresse) && isset($smarty.get.fromCheckout)}
                                    <input type="hidden" name="updateAddress" value="{$Lieferadresse->kLieferadresse}">
                                    <input type="hidden" name="backToCheckout" value="1">
                                    <button type="submit" value="1" class="btn btn-primary btn-block">
                                        {lang key='updateAddressBackToCheckout' section='account data'}
                                    </button>
                                {/if}
                            </div>
                        </div>
                    {/block}
                </form>
            {/block}
            </div>
            {if !$isModal}
            <div class="{block name='account-shipping-address-form-form-address-wrapper-classes'}col-12 col-md-6 shipping-addresses-wrapper{/block}">
            {block name='account-shipping-address-form-form-address-wrapper'}
                <table id="lieferadressen-liste" class="{if $Einstellungen.kaufabwicklung.bestellvorgang_kaufabwicklungsmethode == 'N'}shipping-address-standard-active {/if}table display compact" style="width:100%">
                    <thead>
                    <tr>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                    </tr>
                    </thead>
                    <tbody>
                    {block name='account-shipping-address-form-form-addresses'}
                        {foreach $Lieferadressen as $address}
                            <tr>
                                <td translate="no">
                                    {if $address->cFirma}{$address->cFirma}<br />{/if}
                                    <strong>{if $address->cTitel}{$address->cTitel}{/if} {$address->cVorname} {$address->cNachname}</strong><br />
                                    {$address->cStrasse} {$address->cHausnummer}<br />
                                    {$address->cPLZ} {$address->cOrt}<br />
                                    <div id="deliveryAdditional{$address->kLieferadresse}" class="collapse">
                                        <div class="pt-2">
                                            {block name='account-shipping-address-include-inc-delivery-address'}
                                                {include file='checkout/inc_delivery_address.tpl' Lieferadresse=$address hideMainInfo=true}
                                            {/block}
                                        </div>
                                    </div>
                                    <button translate="yes" class="btn btn-link btn-show-more" data-toggle="collapse" data-target="#deliveryAdditional{$address->kLieferadresse}">
                                        {lang  key='showMore'}
                                    </button>
                                </td>
                                <td class="text-right">
                                    <div class="btn-group">
                                        {if $Einstellungen.kaufabwicklung.bestellvorgang_kaufabwicklungsmethode == 'N' && $address->nIstStandardLieferadresse !== 1}
                                            <button type="button" class="btn btn-outline-secondary btn-sm" data-toggle="tooltip" data-placement="top" title="{lang key='useAsDefaultShippingAddress' section='account data'}" onclick="location.href='{get_static_route id='jtl.php' params=['editLieferadresse' => 1, 'setAddressAsDefault' => {$address->kLieferadresse}, 'token' => {$smarty.session.jtl_token}]}'">
                                                {lang key='setAsStandard' section='account data'}
                                            </button>
                                        {/if}
                                        <button type="button" class="btn btn-secondary btn-sm" data-toggle="tooltip" data-placement="top" title="{lang key='editAddress' section='account data'}" aria-label="{lang key='editAddress' section='account data'}" onclick="location.href='{get_static_route id='jtl.php' params=['editLieferadresse' => 1, 'editAddress' => {$address->kLieferadresse}]}'">
                                            <span class="{et_getIcon key="edit"}"></span>
                                        </button>

                                        <button type="button" class="btn btn-danger btn-sm delete-popup-modal" data-lieferadresse="{$address->kLieferadresse}" data-toggle="tooltip" data-placement="top" title="{lang key='deleteAddress' section='account data'}" aria-label="{lang key='deleteAddress' section='account data'}">
                                            <span class="{et_getIcon key="delete"}"></span>
                                        </button>
                                    </div>
                                </td>
                                <td>
                                    <span class="invisible">
                                        {$address->nIstStandardLieferadresse}
                                    </span>
                                </td>
                            </tr>
                        {/foreach}
                    {/block}
                    </tbody>
                </table>
            {/block}
            </div>
            {/if}
        </div>
    {/block}
    {block name='account-shipping-address-form-script'}
        {inline_script}<script>
        $(document).ready(function () {
            function format(d) {
                return (d.moreAddressData);
            }
            let tableID = '#lieferadressen-liste';
            let table = $(tableID).DataTable( {
                language: {
                    "lengthMenu":        "{lang key='lengthMenu' section='datatables' addslashes=true}",
                    "info":              "{lang key='info' section='datatables' addslashes=true}",
                    "infoEmpty":         "{lang key='infoEmpty' section='datatables' addslashes=true}",
                    "infoFiltered":      "{lang key='infoFiltered' section='datatables' addslashes=true}",
                    "search":            "",
                    "searchPlaceholder": "{lang key='search' section='datatables' addslashes=true}",
                    "zeroRecords":       "{lang key='zeroRecords' section='datatables' addslashes=true}",
                    "paginate": {
                        "first":    "{lang key='paginatefirst' section='datatables' addslashes=true}",
                        "last":     "{lang key='paginatelast' section='datatables' addslashes=true}",
                        "next":     "{lang key='paginatenext' section='datatables' addslashes=true}",
                        "previous": "{lang key='paginateprevious' section='datatables' addslashes=true}"
                    }
                },
                columns: [
                    { data: 'address' },
                    { data: 'buttons' },
                    { data: 'sort' }
                ],
                columnDefs: [
                    {
                        targets: [2],
                        visible: false,
                    }
                ],
                lengthMenu: [ [3, 6, 15, 30, -1], [3, 6, 15, 30, "{lang key='showAll' addslashes=true}"] ],
                pageLength: 3,
                order: [2, 'desc'],
                initComplete: function (settings, json) {
                    $('.dataTables_filter input[type=search]').removeClass('form-control-sm');
                    $('.dataTables_length select').removeClass('custom-select-sm form-control-sm');
                },
                drawCallback: function( settings ) {
                    $('table.dataTable thead').remove();
                },
            } );

            $(tableID + ' tbody').on('click', 'td.dt-control', function () {
                let tr = $(this).closest('tr'),
                    row = table.row(tr);

                if (row.child.isShown()) {
                    row.child.hide();
                    tr.removeClass('shown');
                } else {
                    row.child(format(row.data())).show();
                    tr.addClass('shown');
                }
            });

            $(tableID + ' tbody').on('click', '.delete-popup-modal',function(){
                let lieferadresse = $(this).data('lieferadresse');

                eModal.addLabel('{lang key='yes' section='global' addslashes=true}', '{lang key='no' section='global' addslashes=true}');
                let options = {
                    message: '{lang key='modalShippingAddressDeletionConfirmation' section='account data' addslashes=true}',
                    label: '{lang key='yes' section='global' addslashes=true}',
                    title: '{lang key='deleteAddress' section='account data' addslashes=true}'
                };
                eModal.confirm(options).then(
                    function() {
                        window.location = "{get_static_route id='jtl.php'}?editLieferadresse=1&deleteAddress="+lieferadresse+"&token={$smarty.session.jtl_token}"
                    }
                );
            });
        });
    </script>{/inline_script}
    {/block}
{/block}
