{block name='account-order-details'}
    {et_isShopVersionAtLeast value="5.2.0-beta" assign='shopIsAtLeast52'}
    {et_isShopVersionAtLeast value="5.6.0-rc.2" assign='shopIsAtLeast56'}
    {$lazyLoadImages=$lazyLoadImages|default:true}
    {block name='account-order-details-script-location'}
        <script>
            if (top.location !== self.location) {
                top.location = self.location.href;
            }
        </script>
    {/block}
    {block name='account-order-details-heading'}
        <h1>{lang key='orderCompletedPre' section='checkout'}</h1>
    {/block}
    {block name='account-order-details-order-details-data'}
        <div class="card order-details">
            <div class="card-header">
            {block name='account-order-details-order-heading'}
                <div class="row align-items-center-util">
                    {block name='account-order-details-order-heading-date'}
                        <div class="col col-12 col-lg-3">
                            <div class="order-details-date">
                                <span class="{et_getIcon key="orderCreationDate"}"></span>{$Bestellung->dErstelldatum_de}
                            </div>
                        </div>
                    {/block}
                    <div class="col col-6 col-lg-auto">
                        {lang key='yourOrderId' section='checkout'}: {$Bestellung->cBestellNr}
                    </div>
                    <div class="col col-6 col-lg-auto order-details-status">
                        {lang key='orderStatus' section='login'}: {$Bestellung->Status}
                    </div>
                </div>
            {/block}
            </div>
            {if isset($Kunde) && $Kunde->kKunde > 0}
                <div class="card-body">
                {block name='account-order-details-order-body'}
                    <div class="row">
                        <div class="col col-12 col-lg-3">
                            <ul class="list-unstyled order-details-data">
                                <li>
                                    {block name='account-order-details-payment'}
                                        {lang key='paymentOptions' section='global'}:
                                        <div class="order-details-data-item">
                                            <dl class="list-unstyled">
                                                {if $Bestellung->dBezahldatum_de === '00.00.0000' || empty($Bestellung->dBezahldatum_de)}
                                                    <dt>{$Bestellung->cZahlungsartName}</dt>
                                                    <dd>
                                                        {if ($Bestellung->cStatus == $smarty.const.BESTELLUNG_STATUS_OFFEN || $Bestellung->cStatus == $smarty.const.BESTELLUNG_STATUS_IN_BEARBEITUNG)
                                                        && (($Bestellung->Zahlungsart->cModulId !== 'za_ueberweisung_jtl'
                                                        && $Bestellung->Zahlungsart->cModulId !== 'za_nachnahme_jtl'
                                                        && $Bestellung->Zahlungsart->cModulId !== 'za_rechnung_jtl'
                                                        && $Bestellung->Zahlungsart->cModulId !== 'za_barzahlung_jtl')
                                                        && (isset($Bestellung->Zahlungsart->bPayAgain) && $Bestellung->Zahlungsart->bPayAgain))}
                                                            {if $shopIsAtLeast52}
                                                                <a href="{get_static_route id='bestellabschluss.php'}?payAgain=1&kBestellung={$Bestellung->kBestellung}">
                                                                    {lang key='payNow' section='global'}
                                                                </a>
                                                            {else}
                                                                <a href="{get_static_route id='bestellab_again.php'}?kBestellung={$Bestellung->kBestellung}">
                                                                    {lang key='payNow' section='global'}
                                                                </a>
                                                            {/if}
                                                        {else}
                                                            {lang key='notPayedYet' section='login'}
                                                        {/if}
                                                    </dd>
                                                {elseif !empty($incommingPayments) && $incommingPayments->isEmpty()}
                                                    <dt>{$Bestellung->cZahlungsartName}</dt>
                                                {/if}
                                                {if !empty($incommingPayments)}
                                                    {foreach $incommingPayments as $paymentProvider => $incommingPayment}
                                                        <dt>{htmlentities($paymentProvider)}</dt>
                                                        {foreach $incommingPayment as $payment}
                                                            <dd>{$payment->paymentLocalization}</dd>
                                                        {/foreach}
                                                    {/foreach}
                                                {elseif $Bestellung->cStatus != $smarty.const.BESTELLUNG_STATUS_STORNO && $Bestellung->dBezahldatum_de !== '00.00.0000' && !empty($Bestellung->dBezahldatum_de)}
                                                    {* Shop 5.0.x fallback *}
                                                    <dt>{$Bestellung->cZahlungsartName}</dt>
                                                    <dd>{lang key='payedOn' section='login'} {$Bestellung->dBezahldatum_de}</dd>
                                                {/if}
                                            </dl>
                                        </div>
                                    {/block}
                                </li>
                                <li>
                                    {block name='account-order-details-shipping'}
                                        {lang key='shippingOptions' section='global'}:
                                        <div class="order-details-data-item">
                                            <ul class="list-unstyled">
                                                <li>{$Bestellung->cVersandartName}</li>
                                                {if $Bestellung->cStatus == $smarty.const.BESTELLUNG_STATUS_VERSANDT}
                                                    <li>{lang key='shippedOn' section='login'} {$Bestellung->dVersanddatum_de}</li>
                                                {elseif $Bestellung->cStatus == $smarty.const.BESTELLUNG_STATUS_TEILVERSANDT}
                                                    <li>{$Bestellung->Status}</li>
                                                {else}
                                                    <li><span>{lang key='notShippedYet' section='login'}</span></li>
                                                    {if $Bestellung->cStatus != $smarty.const.BESTELLUNG_STATUS_STORNO}
                                                        <li>
                                                            <span>{lang key='shippingTime' section='global'}: {if isset($cEstimatedDeliveryEx)}{$cEstimatedDeliveryEx}{else}{$Bestellung->cEstimatedDelivery}{/if}</span>
                                                        </li>
                                                    {/if}
                                                {/if}
                                            </ul>
                                        </div>
                                    {/block}
                                </li>
                                <li>
                                    {block name='account-order-details-billing-address'}
                                        {lang key='billingAdress' section='checkout'}:
                                        <span class="order-details-data-item">
                                            {block name='account-order-details-include-inc-billing-address'}
                                                {include file='checkout/inc_billing_address.tpl' orderDetail=true}
                                            {/block}
                                        </span>
                                    {/block}
                                </li>
                                <li>
                                    {block name='account-order-details-shipping-address'}
                                        {lang key='shippingAdress' section='checkout'}:
                                        <span class="order-details-data-item">
                                            {if !empty($Lieferadresse->kLieferadresse)}
                                                {block name='account-order-details-include-inc-delivery-address'}
                                                    {include file='checkout/inc_delivery_address.tpl' orderDetail=true}
                                                {/block}
                                            {else}
                                                {lang key='shippingAdressEqualBillingAdress' section='account data'}
                                            {/if}
                                        </span>
                                    {/block}
                                </li>
                                {if isset($Einstellungen.global.global_rma_enabled) && $Einstellungen.global.global_rma_enabled === 'Y' && $rmaLink|default:'' !== ''}
                                    {block name='et-account-order-details-rma-button-wrapper'}
                                    <li>
                                        {block name='account-order-details-rma-button'}
                                        <a href="{$rmaLink}" class="btn btn-outline-primary" aria-label="{lang key='rma' section='rma'}: {lang key='rma_artikelwahl' section='rma'}" title="{lang key='rma' section='rma'}: {lang key='rma_artikelwahl' section='rma'}">
                                            <i class="{et_getIcon key="redo"}"></i>
                                            {lang key='createRetoure' section='rma'}
                                        </a>
                                        {/block}
                                    </li>
                                    {/block}
                                {/if}
                            </ul>
                        </div>
                        <div class="col col-12 col-lg-9">
                            {block name='et-account-order-details-order-subheading-basket-loggedin'}
                                {block name='account-order-details-order-subheading-basket'}
                                    <span class="subheadline">{lang key='basket'}</span>
                                {/block}
                            {/block}
                            {block name='et-account-order-details-include-order-item-loggedin'}
                                {block name='account-order-details-include-order-item'}
                                    {include file='account/order_item.tpl' tplscope='confirmation' lazyLoadImages=$lazyLoadImages}
                                {/block}
                            {/block}
                        </div>
                    </div>
                    {/block}
                </div>
            {else}
                <div class="card-body order-details-request-plz">
                    {block name='account-order-details-request-plz'}
                        <div class="row">
                            <div class="col col-12 col-md-6">
                                <form method="post" id='request-plz' action="{get_static_route}" class="jtl-validate label-slide">
                                    {csrf_token}

                                    <input type="hidden" name="uid" value="{$uid}" />
                                    {if $shopIsAtLeast56}
                                        <p>{lang key='enter_plz_and_mail_for_details' section='account data'}</p>
                                    {else}
                                        <p>{lang key='enter_plz_for_details' section='account data'}</p>
                                    {/if}
                                    {formgroup
                                        label-for="postcode"
                                        label={lang key='plz' section='account data'}
                                    }
                                        <input
                                            type="text"
                                            name="plz"
                                            value=""
                                            id="postcode"
                                            class="postcode_input form-control"
                                            placeholder=" "
                                            required
                                            autocomplete="billing postal-code"
                                        />
                                    {/formgroup}
                                    {if $shopIsAtLeast56}
                                        {formgroup
                                            label-for="mailaddress"
                                            label={lang key='email' section='account data'}
                                        }
                                            <input
                                                type="text"
                                                name="mail"
                                                value=""
                                                id="mailaddress"
                                                class="mailaddress_input form-control"
                                                placeholder=" "
                                                required
                                                autocomplete="billing mail-address"
                                            />
                                        {/formgroup}
                                    {/if}
                                    <div class="row">
                                        <div class="col ml-auto-util col-md-auto">
                                            {if $shopIsAtLeast56}
                                                {include file="widgets/base/button.tpl" type="submit" value="1" variant="primary" classes="btn-block mb-3" label="{lang key='view_order_details' section='global'}"}
                                            {else}
                                                {include file="widgets/base/button.tpl" type="submit" value="1" variant="primary" classes="btn-block mb-3" label="{lang key='view' section='global'}"}
                                            {/if}
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="col col-12 col-md-9">
                                {block name='et-account-order-details-order-subheading-basket-guest'}
                                    {block name='account-order-details-order-subheading-basket'}
                                        <span class="subheadline">{lang key='basket'}</span>
                                    {/block}
                                {/block}
                                {block name='et-account-order-details-include-order-item-guest'}
                                    {block name='account-order-details-include-order-item'}
                                        {include file='account/order_item.tpl' tplscope='confirmation' lazyLoadImages=$lazyLoadImages}
                                    {/block}
                                {/block}
                            </div>
                        </div>
                    {/block}
                </div>
            {/if}
        </div>
    {/block}

    {if isset($Kunde) && $Kunde->kKunde > 0}
        {block name='account-order-details-include-downloads'}
            {include file='account/downloads.tpl'}
        {/block}
        {block name='account-order-details-include-uploads'}
            {include file='account/uploads.tpl'}
        {/block}

        {if isset($Bestellung->oLieferschein_arr) && count($Bestellung->oLieferschein_arr) > 0}
            {block name='account-order-details-delivery-note-content'}
                <div class="h2">{if $Bestellung->cStatus == $smarty.const.BESTELLUNG_STATUS_TEILVERSANDT}{lang key='partialShipped' section='order'}{else}{lang key='shipped' section='order'}{/if}</div>
                <div class="table-responsive mb-3">
                    <table class="table table-striped table-bordered">
                        <thead>
                            {block name='account-order-details-delivery-note-header'}
                                <tr>
                                    <th>{lang key='shippingOrder' section='order'}</th>
                                    <th>{lang key='shippedOn' section='login'}</th>
                                    <th class="text-right-util">{lang key='packageTracking' section='order'}</th>
                                </tr>
                            {/block}
                        </thead>
                        <tbody>
                            {block name='account-order-details-delivery-notes'}
                                {foreach $Bestellung->oLieferschein_arr as $oLieferschein}
                                    <tr>
                                        <td><a data-toggle="modal" data-target="#shipping-order-{$oLieferschein->getLieferschein()}" id="{$oLieferschein->getLieferschein()}" href="#" title="{$oLieferschein->getLieferscheinNr()}">{$oLieferschein->getLieferscheinNr()}</a></td>
                                        <td>{$oLieferschein->getErstellt()|date_format:"d.m.Y H:i"}</td>
                                        <td class="text-right-util">
                                            {foreach $oLieferschein->oVersand_arr as $oVersand}
                                                {if $oVersand->getIdentCode()}
                                                    <p><a href="{$oVersand->getLogistikVarUrl()}" target="_blank" class="shipment" title="{$oVersand->getIdentCode()}">{lang key='packageTracking' section='order'}</a></p>
                                                {/if}
                                            {/foreach}
                                        </td>
                                    </tr>
                                {/foreach}
                            {/block}
                        </tbody>
                    </table>
                </div>

                {* Lieferschein Popups *}
                {foreach $Bestellung->oLieferschein_arr as $oLieferschein}
                    {block name='account-order-details-delivery-note-popup'}
                        <div tabindex="-1"
                            id="shipping-order-{$oLieferschein->getLieferschein()}"
                            class="fade shipping-order-modal modal"
                        >
                            <div class="modal-dialog modal-lg" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title">
                                            {if $Bestellung->cStatus == $smarty.const.BESTELLUNG_STATUS_TEILVERSANDT}
                                                {lang key='partialShipped' section='order'}
                                            {else}
                                                {lang key='shipped' section='order'}
                                            {/if}
                                        </h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="{lang key='close' section='account data'}">
                                            <i class="{et_getIcon key="close"}"></i>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                        {block name='account-order-details-delivery-note-popup-heading'}
                                            <div class="shipping-order-modal-mb">
                                                <strong>{lang key='shippingOrder' section='order'}</strong>: {$oLieferschein->getLieferscheinNr()}<br />
                                                <strong>{lang key='shippedOn' section='login'}</strong>: {$oLieferschein->getErstellt()|date_format:"d.m.Y H:i"}<br />
                                            </div>
                                        {/block}
                                        {if $oLieferschein->getHinweis() !== null && strlen($oLieferschein->getHinweis()) > 0}
                                            {block name='account-order-details-delivery-note-popup-alert'}
                                                <div role="alert" class="alert alert-info shipping-order-modal-mb">
                                                    {$oLieferschein->getHinweis()}
                                                </div>
                                            {/block}
                                        {/if}
                                        {block name='account-order-details-delivery-note-popup-tracking'}
                                            <div class="shipping-order-modal-mb">
                                                {foreach $oLieferschein->oVersand_arr as $oVersand}
                                                    {if $oVersand->getIdentCode()}
                                                        <p>
                                                            <a href="{$oVersand->getLogistikVarUrl()}" target="_blank" class="shipment" title="{$oVersand->getIdentCode()}">
                                                                {lang key='packageTracking' section='order'}
                                                            </a>
                                                        </p>
                                                    {/if}
                                                {/foreach}
                                            </div>
                                        {/block}
                                        {block name='account-order-details-delivery-note-popup-table'}
                                            {$hasPositions=false}
                                            {foreach $oLieferschein->oLieferscheinPos_arr as $oLieferscheinpos}
                                                {if $oLieferscheinpos->oPosition->cName|default:'' !== ''}
                                                    {$hasPositions=true}
                                                {/if}
                                            {/foreach}
                                            {if $hasPositions}
                                            <table class="table table-striped">
                                                <thead>
                                                <tr>
                                                    <th>{lang key="partialShippedPosition" section="order"}</th>
                                                    <th>{lang key="partialShippedCount" section="order"}</th>
                                                    <th>{lang key='productNo' section='global'}</th>
                                                    <th>{lang key='product' section='global'}</th>
                                                    <th>{lang key="order" section="global"}</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                {foreach $oLieferschein->oLieferscheinPos_arr as $oLieferscheinpos}
                                                    {if $oLieferscheinpos->oPosition->cName|default:'' === ''}
                                                        {continue}
                                                    {/if}
                                                    <tr>
                                                        <td>{$oLieferscheinpos@iteration}</td>
                                                        <td>{$oLieferscheinpos->getAnzahl()}</td>
                                                        <td>{$oLieferscheinpos->oPosition->cArtNr|default:''}</td>
                                                        <td>
                                                            {$oLieferscheinpos->oPosition->cName}
                                                            <ul class="list-unstyled text-muted-util small">
                                                                {if !empty($oLieferscheinpos->oPosition->cHinweis)}
                                                                    <li class="text-info notice">{$oLieferscheinpos->oPosition->cHinweis}</li>
                                                                {/if}

                                                                {* Artikel property is not set on free gifts and maybe some other position types *}
                                                                {if isset($oLieferscheinpos->oPosition->Artikel)}
                                                                    {* eindeutige Merkmale *}
                                                                    {if $oLieferscheinpos->oPosition->Artikel->cHersteller && $Einstellungen.artikeldetails.artikeldetails_hersteller_anzeigen !== "N"}
                                                                        <li class="manufacturer">
                                                                            <strong>{lang key='manufacturer' section='productDetails'}</strong>:
                                                                            <span class="values">
                                                                            {$oLieferscheinpos->oPosition->Artikel->cHersteller}
                                                                            </span>
                                                                        </li>
                                                                    {/if}

                                                                    {if $Einstellungen.kaufabwicklung.bestellvorgang_artikelmerkmale == 'Y' && !empty($oLieferscheinpos->oPosition->Artikel->oMerkmale_arr)}
                                                                        {if $shopIsAtLeast52}
                                                                            {foreach $oLieferscheinpos->oPosition->Artikel->oMerkmale_arr as $characteristic}
                                                                                <li class="characteristic">
                                                                                    <strong>{$characteristic->getName()|escape:'html'}</strong>:
                                                                                    <span class="values">
                                                                                        {foreach $characteristic->getCharacteristicValues() as $characteristicValue}
                                                                                            {if !$characteristicValue@first}, {/if}
                                                                                            {$characteristicValue->getValue()}
                                                                                        {/foreach}
                                                                                    </span>
                                                                                </li>
                                                                            {/foreach}
                                                                        {else}
                                                                            {foreach $oLieferscheinpos->oPosition->Artikel->oMerkmale_arr as $oMerkmale_arr}
                                                                                <li class="characteristic">
                                                                                    <strong>{$oMerkmale_arr->cName|escape:'html'}</strong>:
                                                                                    <span class="values">
                                                                                        {foreach $oMerkmale_arr->oMerkmalWert_arr as $oWert}
                                                                                            {if !$oWert@first}, {/if}
                                                                                            {$oWert->cWert}
                                                                                        {/foreach}
                                                                                    </span>
                                                                                </li>
                                                                            {/foreach}
                                                                        {/if}
                                                                    {/if}
                                                                {/if}
                                                            </ul>
                                                        </td>
                                                        <td>{$Bestellung->cBestellNr}</td>
                                                    </tr>
                                                {/foreach}
                                                </tbody>
                                            </table>
                                            {/if}
                                        {/block}
                                    </div>
                                </div>
                            </div>
                        </div>
                    {/block}
                {/foreach}
            {/block}
        {/if}

        {block name='account-order-details-order-comment'}
            {if $Bestellung->cKommentar !== null && !empty(trim($Bestellung->cKommentar))}
                <div class="h3">{lang key='yourOrderComment' section='login'}</div>
                <p translate="no">{$Bestellung->cKommentar}</p>
            {/if}
        {/block}
        {block name='account-order-details-actions'}
            <div class="row btn-row">
                <div class="col col-md-3 col-12">
                    {include file="widgets/base/button.tpl" variant="secondary" classes="btn-back btn-block" href="{get_static_route id='jtl.php'}?bestellungen=1" title="{lang key='back'}" label="{lang key='back'}" iconPosition="left" icon="{et_getIcon key="navigationPrevious"}"}
                </div>
            </div>
        {/block}
    {/if}
{/block}
