<?php

defined('ABSPATH') || die('Access Denied');

wp_enqueue_script('wde_' . $this->_layout);
wp_enqueue_style('wde_' . $this->_layout);

$options = $this->options;

$final_checkout_data = $this->final_checkout_data;
$products_data = $final_checkout_data['products_data'];
$shipping_method = $final_checkout_data['shipping_method'];

$total_price_text = $final_checkout_data['total_price_text'];

$payment_buttons_data = $this->payment_buttons_data;
$pager_data = $this->pager_data;
?>
<form name="wd_shop_main_form" action="" method="POST"></form>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <!-- panel -->
      <div class="wd_shop_panel_user_data panel panel-default">
        <div class="panel-body">
          <h2 class="wd_shop_header"><?php _e('Confirm order', 'wde'); ?></h2>
          <?php
          foreach ($products_data as $product_data) {
            ?>
          <div class="wd_shop_order_product_container col-sm-12">
            <div class="row">
              <!-- name -->
              <div class="col-sm-12">
                <h4 class="wd_shop_order_product_name wd_shop_product_name_all wd_shop_header_sm">
                  <?php echo $product_data->name; ?>
                </h4>
              </div>
              <div class="col-sm-8">
                <div class="row">
                  <!-- image -->
                  <div class="col-sm-4">
                    <div class="row">
                      <div class="wd_shop_order_product_image_container wd_center_wrapper col-sm-12">
                        <div>
                          <?php 
                          if ($product_data->image != '') {
                            ?>
                            <img class="wd_shop_order_product_image" src="<?php echo $product_data->image; ?>" />
                            <?php
                          }
                          else {
                            ?>
                            <div class="wd_shop_order_product_no_image">
                              <span class="glyphicon glyphicon-picture"></span>
                              <br />
                              <span><?php _e('No Image', 'wde'); ?></span>
                            </div>
                            <?php
                          }
                          ?>
                        </div>
                      </div>
                    </div>
                  </div>
                  <!-- info -->
                  <div class="col-sm-8">
                    <!-- parameters -->
                    <?php
                    if ($product_data->parameters != '') {
                      ?>
                      <p>
                        <strong><?php _e('Parameters', 'wde'); ?>:</strong><br />
                        <?php echo str_replace(', ', '<br />', $product_data->parameters); ?>
                      </p>
                      <?php
                    }
                    ?>
                    <!-- shipping -->
                    <?php
                    if (($product_data->enable_shipping == 1 or ($product_data->enable_shipping == 2 /*&& $options->checkout_enable_shipping == 1*/)) && ($product_data->shipping_method_name != '')) {
                      ?>
                      <p>
                        <strong><?php _e('Shipping', 'wde'); ?>:</strong>
                        <?php echo $product_data->shipping_method_name; ?>
                      </p>
                      <?php
                    }
                    ?>
                  </div>
                </div>
              </div>
              <div class="col-sm-4 text-right">
                <?php
                if ($product_data->price_text) {
                  ?>
                <!-- price -->
                <p class="wd_shop_order_product_price_container">
                  <span class="wd_shop_order_product_price wd_shop_product_price_all">
                    <?php echo $product_data->price_text; ?>
                  </span>
                </p>
                  <?php
                }
                if ($product_data->discount_rate) {
                  ?>
                <!-- price -->
                <p class="wd_shop_order_product_discount_container wd_shop_product_price_all">
                  <span>
                    <?php _e("Discount", 'wde'); ?>:
                  </span>
                  <span>
                    <?php echo $product_data->discount_rate; ?>
                  </span>
                </p>
                  <?php
                }
                if ($product_data->shipping_method_price_text) {
                  ?>
                <!-- shipping -->
                <p class="wd_shop_order_product_shipping_price_container wd_shop_product_price_all">
                  <span>
                    <?php _e("Shipping", 'wde'); ?>:
                  </span>
                  <span>
                    <?php echo $product_data->shipping_method_price_text; ?>
                  </span>
                </p>
                  <?php
                }
                if ($product_data->tax_price_text) {
                  ?>
                <!-- tax -->
                <p class="wd_shop_order_product_tax_price_container wd_shop_product_price_all">
                  <span>
                    <?php _e("Tax", 'wde'); ?>:
                  </span>
                  <span>
                    <?php echo $product_data->tax_price_text; ?>
                  </span>
                </p>
                  <?php
                }
                ?>
                <!-- count -->
                <p class="wd_shop_order_product_quantity_container">
                  <span>
                    <?php _e("Quantity", 'wde'); ?>:
                  </span>
                  <span>
                    <?php echo $product_data->count; ?>
                  </span>
                </p>                
              </div>
            </div>
          </div>
            <?php
            if ($product_data->subtotal_price_text) {
              ?>
          <div class="row">
            <div class="col-sm-12 text-right">
              <!-- subtotal -->
              <p>
                <span class="wd_shop_order_product_subtotal_title wd_shop_product_price_all">
                  <?php _e('Subtotal', 'wde'); ?>:
                </span>
                <span class="wd_shop_order_product_subtotal wd_shop_product_price_all">
                  <?php echo $product_data->subtotal_price_text; ?>
                </span>
              </p>
            </div>
          </div>
              <?php
            }
            ?>
          <div class="row"><div class="col-sm-12"><div class="wd_divider"></div></div></div>
            <?php
          }
          if ($shipping_method->shipping_method_price_text) {
            ?>
          <div class="row">
            <!-- total -->
            <div class="col-sm-12 text-right">
              <span class="wd_shop_total_title wd_shop_product_price_all">
                <?php _e('Shipping', 'wde'); ?>:
              </span>
              <span class="wd_shop_total wd_shop_product_price_all">
                <?php echo $shipping_method->shipping_method_price_text; ?>
              </span>
            </div>
          </div>
            <?php
          }
          if ($total_price_text) {
            ?>
          <div class="row">
            <!-- total -->
            <div class="col-sm-12 text-right">
              <span class="wd_shop_total_title wd_shop_product_price_all">
                <?php _e('Total price', 'wde'); ?>:
              </span>
              <span class="wd_shop_total wd_shop_product_price_all">
                <?php echo $total_price_text; ?>
              </span>
            </div>
          </div>
          <div class="row"><div class="col-sm-12"><div class="wd_divider"></div></div></div>
            <?php
          }
          ?>
          <div class="row">
            <div class="col-sm-12">
              <?php
              foreach ($payment_buttons_data as $payment_button_data) {
                ?>
                <p class="text-right">
                  <a href="<?php echo $payment_button_data->action; ?>"
                     class="btn btn-primary"
                     onclick="wdShop_onBtnCheckoutClick(event, this); return false;">
                    <?php echo $payment_button_data->text; ?>
                  </a>
                </p>
                <?php
              }
              ?>
            </div>
          </div>
        </div>
      </div>
      <!-- pager -->
      <div>
        <ul class="pager">
          <?php
          $btn_cancel_checkout_data = $pager_data['btn_cancel_checkout_data'];
          ?>
          <li class="previous">
            <a href="<?php echo $btn_cancel_checkout_data['url']; ?>">
              <span><?php _e('Cancel checkout', 'wde'); ?></span>
            </a>
          </li>
          <?php
          if (isset($pager_data['btn_prev_page_data'])) {
            $btn_prev_page_data = $pager_data['btn_prev_page_data'];
            ?>
            <li class="previous">
              <a href="<?php echo $btn_prev_page_data['action']; ?>"
                 onclick="onWDShop_pagerBtnClick(event, this); return false;">
                <span class="glyphicon glyphicon-arrow-left"></span>&nbsp;
                <span><?php echo $btn_prev_page_data['text']; ?></span>
              </a>
            </li>
            <?php
          }
          if (isset($pager_data['btn_next_page_data'])) {
            $btn_next_page_data = $pager_data['btn_next_page_data'];
            ?>
            <li class="next">
              <a href="<?php echo $btn_next_page_data['action']; ?>"
                 onclick="onWDShop_pagerBtnClick(event, this); return false;">
                <span><?php echo $btn_next_page_data['text']; ?></span>&nbsp;
                <span class="glyphicon glyphicon-arrow-right"></span>
              </a>
            </li>
            <?php
          }
          ?>
        </ul>
      </div>
    </div>
  </div>
</div>