<?php echo $header; ?>

<?php
    if ($this->config->get('wg24_seo_fer_facebook_status')=='enable'){
      if (!$this->config->get('wg24_seo_fer_facebook_pixel')==''){
?>

<?php if (isset($google_merchant_center_status)) { ?>
  <script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer>
  </script>
  
  <script>
    const google_merchant_center_merchant_id = <?php echo json_encode($google_merchant_center_merchant_id) ?> ;
    const google_merchant_center_order_id = <?php echo json_encode($google_merchant_center_order_id) ?> ;
    const google_merchant_center_email = <?php echo json_encode($google_merchant_center_email) ?> ;
    const google_merchant_center_country = <?php echo json_encode($google_merchant_center_country) ?> ;
    const google_merchant_center_delivery_date = <?php echo json_encode($google_merchant_center_delivery_date) ?> ;
    const google_merchant_center_opt_in_style = <?php echo json_encode($google_merchant_center_opt_in_style) ?> ;


    function renderOptIn() {
      window.gapi.load('surveyoptin', function() {
        window.gapi.surveyoptin.render({
          merchant_id: `${google_merchant_center_merchant_id}`,
          order_id: `${google_merchant_center_order_id}`,
          email: `${google_merchant_center_email}`,
          delivery_country: `${google_merchant_center_country}`,
          estimated_delivery_date: `${google_merchant_center_delivery_date}`,
          opt_in_style: `${google_merchant_center_opt_in_style}`
        });
      });

      window.___gcfg = {
        lang: "pt-BR"
      };
    }
  </script>
<?php } ?>

<script>
  window.waitEvent('scripts_document', function() {
    fbq('track', 'Purchase', {currency : "BRL", value : <?php echo $order_total; ?>});

    var btnGetnetReload = document.querySelector('.js-reloadPayment');

    if (btnGetnetReload) {
      btnGetnetReload.addEventListener('click', function(e) {
        reloadPix()
      });
    }

    function reloadPix() {
      $.ajax({
        url: 'index.php?route=payment/getnet/reloadPix',
        type: 'get',
        dataType: 'json',
        timeout: 3000,
        contentType: 'application/json; charset=utf-8',
        error: function(xhr, ajaxOptions, thrownError) {
          console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
        },
        success: function(json) {
          if (json.pay) {
            var imgQR = document.querySelector('.js-imgQr');
            var spanQr = document.querySelector('.js-copy-content');
            imgQR.setAttribute('src', 'https://chart.googleapis.com/chart?chs=400x400&cht=qr&chl=' + json
              .additional_data.qr_code);
            spanQr.textContent = json.additional_data.qr_code;
          }
        },
      });
    }

    setInterval(paymentStatus, 5000);

    function paymentStatus() {
      var imgQR = document.querySelector('.js-imgQr');
      if (imgQR && !(imgQR.getAttribute('src') == 'image/qrcode_pago.png')) {
        $.ajax({
          url: 'index.php?route=checkout/success/verifyPaymentPix',
          type: 'get',
          dataType: 'json',
          timeout: 3000,
          contentType: 'application/json; charset=utf-8',
          error: function(xhr, ajaxOptions, thrownError) {
            console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
          },
          success: function(json) {
            if (json) {
              imgQR.setAttribute('src', 'image/qrcode_pago.png');
            }
          },
        });
      }
    }
  });
</script>
<?php
      }
    }
?>

<section class="container-fluid" <?php if ($transaction && $transactionItens) { ?>
  data-transaction='{"details": <?php echo json_encode($transaction) ?>, 
    "products": <?php echo json_encode($transactionItens) ?>, "googleTrackingCodes": <?php echo json_encode($googleAnalytics)?>}'
  <?php } ?>
  >

  <div class="row">
    <div class="col-xs col-sm-12 col-md-8">
      <div class="content-box svn-teste-sucesso">

        <?php echo $breadcrumbs; ?>

        <?php if ($content_top) { ?>
          <?php echo $content_top; ?>
        <?php } ?>

        <div class="content-box">
				  <div class="background-base-content">

            <h3 class="text-dark-opacity">
              <?php echo $heading_title; ?>
            </h3>

            <div class="box-shadow-dark rounded-medium background-white flex middle-xs full-width padding-medium">
            
              <div class="col-xs-12 col-sm-12 col-md-12 no-padding">
                <?php echo $payment_template; ?> 
              </div>

              <div class="col-xs-12 col-sm-12 col-md-12 no-padding vertical-padding-medium">
                <div class="text-medium text-gray">
                  <?php echo $text_message; ?>
                 </div>
              </div>
              
              <div class="flex btn-account">
                <a
                  class="btn-default btn-medium btn-neutral-black btn-account-right-margin" 
                  title="Ver pedido"
                  type="button"
                  href="<?php echo $order; ?>"
                >
                  <span >Ver pedido</span>
                </a>

                <a
                  type="button"
                  class="btn-default btn-medium btn-neutral-white"
                  title="Contate-nos"
                  href="<?php echo $contact; ?>"
                >
                  <span>Entrar em contato</span>
                </a>
              </div>
              
            </div>
          </div>
        </div>  

        <?php if (isset($checkout_success) && isset($certificate_ebit_status) && $certificate_ebit_status) { ?>
        <div>
          <a id="bannerEbit"></a>
          <param id="ebitParam"
            value="email=<?php echo $certificate_ebit_info['email']; ?>&gender=<?php echo $certificate_ebit_info['gender']; ?>&birthDay=<?php echo $certificate_ebit_info['birthDay']; ?>&zipCode=<?php echo $certificate_ebit_info['zipCode']; ?>&mktSaleID=<?php echo $certificate_ebit_info['mktSaleID']; ?>&deliveryTax=<?php echo $certificate_ebit_info['deliveryTax']; ?>&totalSpent=<?php echo $certificate_ebit_info['totalSpent']; ?>&value=<?php echo $certificate_ebit_info['value']; ?>&quantity=<?php echo $certificate_ebit_info['quantity']; ?>&productName=<?php echo $certificate_ebit_info['productName']; ?>&transactionId=<?php echo $certificate_ebit_info['transactionId']; ?>&ean=<?php echo $certificate_ebit_info['eanCode']; ?>&sku=<?php echo $certificate_ebit_info['sku']; ?>&buscapeId=<?php echo $certificate_ebit_info['buscapeId']; ?>&storeId=<?php echo $certificate_ebit_info['storeId']; ?>&plataform=<?php echo $certificate_ebit_info['plataform']; ?>" />
        </div>
        <?php } ?>

      </div>
    </div>

    <?php if ($column_right) { ?>
      <div class="hidden-md-down col-md-3">
        <?php echo $column_right; ?>
      </div>
    <?php } ?>

    <?php if ($content_bottom) { ?>
      <div class="col-xs-12">
        <?php echo $content_bottom; ?>
      </div>
    <?php } ?>

  </div>
</section>

<?php echo $footer; ?>