{*
* @Module Name: AP Page Builder
* @Website: apollotheme.com - prestashop template provider
* @author Apollotheme <apollotheme@gmail.com>
* @copyright Apollotheme
* @description: ApPageBuilder is module help you can build content for your shop
*}
{extends file='page.tpl'}

{block name='page_content_container' prepend}
    <section id="content-hook_order_confirmation" class="card">
      <div class="card-block">
        <div class="row">
          <div class="col-md-12">

            {block name='order_confirmation_header'}
              <h3 class="h1 card-title">
                <i class="material-icons rtl-no-flip done">&#xE876;</i>{l s='Your order is confirmed' d='Shop.Theme.Checkout'}
              </h3>
            {/block}

            <p>
              {l s='An email has been sent to your mail address %email%.' d='Shop.Theme.Checkout' sprintf=['%email%' => $customer.email]}
              {if $order.details.invoice_url}
                {* [1][/1] is for a HTML tag. *}
                {l
                  s='You can also [1]download your invoice[/1]'
                  d='Shop.Theme.Checkout'
                  sprintf=[
                    '[1]' => "<a href='{$order.details.invoice_url}'>",
                    '[/1]' => "</a>"
                  ]
                }
              {/if}
            </p>
            {literal}
              <!-Image Pixel - Mandatory -->
              <img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=27684&amount={/literal}{$order.subtotals.products.amount}{literal}&cr={/literal}{$currency.iso_code}{literal}&ref={/literal}{$order.details.reference}{literal}&parts=DEFAULT:{/literal}{$order.subtotals.products.amount}{literal}&vc=&ch=aw&testmode=0" border="0" width="0" height="0">
              <!-- JavaScript Tracking - Mandatory -->
              <script type="text/javascript">
              //<![CDATA[ /*** Do not change ***/
              var AWIN = {};
              AWIN.Tracking = {};
              AWIN.Tracking.Sale = {};
              /*** Set your transaction parameters ***/
              AWIN.Tracking.Sale.amount = "{/literal}{$order.subtotals.products.amount}{literal}";
              AWIN.Tracking.Sale.orderRef = "{/literal}{$order.details.reference}{literal}";
              AWIN.Tracking.Sale.parts = "DEFAULT:{/literal}{$order.subtotals.products.amount}{literal}";
              AWIN.Tracking.Sale.voucher = "";
              AWIN.Tracking.Sale.currency = "{/literal}{$currency.iso_code}{literal}";
              AWIN.Tracking.Sale.test = "0";
              AWIN.Tracking.Sale.channel = "aw";
              //]]>
              </script>
            {/literal}

            {block name='hook_order_confirmation'}
              {$HOOK_ORDER_CONFIRMATION nofilter}
            {/block}

          </div>
        </div>
      </div>
    </section>
{/block}

{block name='page_content_container'}
  <section id="content" class="page-content page-order-confirmation card">
    <div class="card-block">
      <div class="row">

        {block name='order_confirmation_table'}
          {include
            file='checkout/_partials/order-confirmation-table.tpl'
            products=$order.products
            subtotals=$order.subtotals
            totals=$order.totals
            labels=$order.labels
            add_product_link=false
          }
        {/block}

        {block name='order_details'}
          <div id="order-details" class="col-md-4">
            <h3 class="h3 card-title">{l s='Order details' d='Shop.Theme.Checkout'}:</h3>
            <ul>
              <li>{l s='Order reference: %reference%' d='Shop.Theme.Checkout' sprintf=['%reference%' => $order.details.reference]}</li>
              {php}
                $user_group = Customer::getDefaultGroupId( Context::getContext() -> customer -> id );
                if ( $user_group >= 4 )
                {
                  {/php}
                    {if $order.details.payment == 'Płatności elektroniczne'}
                      <li>{l s='Payment method: %method%' d='Shop.Theme.Checkout' sprintf=['%method%' => 'Przedpłata / Przelew']}</li>
                    {else}
                      <li>{l s='Payment method: %method%' d='Shop.Theme.Checkout' sprintf=['%method%' => $order.details.payment]}</li>
                    {/if}
                  {php}
                }
                else
                {
                  {/php}
                    <li>{l s='Payment method: %method%' d='Shop.Theme.Checkout' sprintf=['%method%' => $order.details.payment]}</li>
                  {php}
                }
              {/php}
              {if !$order.details.is_virtual}
                <li>
                  {if $order.carrier.name == 'Odbiór osobisty' && $language.id == 2}
                    Shipping method: Pickup in person<br/>
                  {elseif $order.carrier.name == 'Odbiór osobisty' && $language.id == 1}
                    Metoda dostawy: odbiór osobisty<br/>
                  {elseif $order.carrier.name == 'Kurier' && $language.id == 2 }
                    Shipping method: Courier
                  {elseif $order.carrier.name == 'Kurier DPD' && $language.id == 2 }
                    Shipping method: DPD Courier
                  {elseif $order.carrier.name == 'Kurier DPD - za pobraniem' && $language.id == 2 }
                    Shipping method: DPD Courier - cash on delivery
                  {else}
                    {l s='Shipping method: %method%' d='Shop.Theme.Checkout' sprintf=['%method%' => $order.carrier.name]}<br>
                  {/if}
                  <em>{$order.carrier.delay}</em>
                </li>
              {/if}
            </ul>
          </div>
        {/block}

      </div>
    </div>
  </section>

  {block name='hook_payment_return'}
    {if ! empty($HOOK_PAYMENT_RETURN)}
    <section id="content-hook_payment_return" class="card definition-list">
      <div class="card-block">
        <div class="row">
          <div class="col-md-12">
            {$HOOK_PAYMENT_RETURN nofilter}
          </div>
        </div>
      </div>
    </section>
    {/if}
  {/block}
  {php}
    $user_group = Customer::getDefaultGroupId( Context::getContext() -> customer -> id );
    if ( $user_group >= 4 )
    {
      $order = Context::getContext() -> smarty->getTemplateVars( 'order' );
      if ( $order['details']['module'] == 'ps_wirepayment' ):
      {/php}
        {if $language.id == 2 }
          {literal}
            <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
            <script type="text/javascript">
              $( function() {
                $( '#content-hook_payment_return .col-md-12 p:first-child' ).html( 'Your order on Redline is ready. <br> Prepayment - you will pay after receiving the invoice <br/> Bank transfer - you will pay on the agreed date, applies only to distributors.' );
                $( '#content-hook_payment_return .col-md-12 dl dd:nth-child(8)' ).hide();
                $( '#content-hook_payment_return .col-md-12 dl dt:nth-child(7)' ).hide();
                $( '#content-hook_payment_return .col-md-12 dl dd:nth-child(6)' ).hide();
                $( '#content-hook_payment_return .col-md-12 dl dt:nth-child(5)' ).hide();
                $( '#content-hook_payment_return .col-md-12 p:nth-child(3)' ).html('We also sent you this information by email.');
                $( '#content-hook_payment_return .col-md-12 strong:nth-child(4)' ).hide();
              });
            </script>
          {/literal}
        {else}
          {literal}
            <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
            <script type="text/javascript">
              $( function() {
                $( '#content-hook_payment_return .col-md-12 p:first-child' ).html( 'Twoje zamówienie na Redline jest gotowe.<br>Przedpłata - zapłacisz po otrzymaniu faktury<br/>Przelew - zapłacisz w uzgodnionym terminie, dotyczy wyłącznie dystrybutorów.' );
                $( '#content-hook_payment_return .col-md-12 dl dd:nth-child(8)' ).hide();
                $( '#content-hook_payment_return .col-md-12 dl dt:nth-child(7)' ).hide();
                $( '#content-hook_payment_return .col-md-12 dl dd:nth-child(6)' ).hide();
                $( '#content-hook_payment_return .col-md-12 dl dt:nth-child(5)' ).hide();
                $( '#content-hook_payment_return .col-md-12 p:nth-child(3)' ).html('Wysłaliśmy Ci te informacje również przez email.');
                $( '#content-hook_payment_return .col-md-12 strong:nth-child(4)' ).hide();
              });
            </script>
          {/literal}
        {/if}
      {php}
      endif;
    }
  {/php}

  {block name='customer_registration_form'}
    {if $customer.is_guest}
      <div id="registration-form" class="card">
        <div class="card-block">
          <h4 class="h4">{l s='Save time on your next order, sign up now' d='Shop.Theme.Checkout'}</h4>
          {render file='customer/_partials/customer-form.tpl' ui=$register_form}
        </div>
      </div>
    {/if}
  {/block}

  {block name='hook_order_confirmation_1'}
    {hook h='displayOrderConfirmation1'}
  {/block}

  {block name='hook_order_confirmation_2'}
    <section id="content-hook-order-confirmation-footer">
      {hook h='displayOrderConfirmation2'}
    </section>
  {/block}
{/block}
