<?php
 
defined('ABSPATH') || die('Access Denied');

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

$options = $this->options;

$pagination = $this->pagination;
$order_rows = $this->order_rows;
?>
<form name="wd_shop_main_form" action="" method="POST">
  <input type="hidden" name="pagination_limit_start" value="<?php //echo $pagination->limitstart; ?>">
  <input type="hidden" name="pagination_limit" value="<?php //echo $pagination->limit; ?>">
</form>

<div class="container">
  <h1 class="wd_shop_header">
    <?php _e('Orders', 'wde'); ?>
  </h1>
  <div class="row">
    <div class="col-sm-12">
      <?php require WD_E_DIR . '/frontend/views/products/tmpl/displayproducts_bartop.php'; ?>
    </div>
  </div>
  <?php
  if (empty($order_rows) == false) {
    ?>
    <div class="row">
      <?php
      for ($i = 0; $i < count($order_rows); $i++) {
          $order_row = $order_rows[$i];
          ?>
          <div class="wd_shop_order_container col-sm-12"
               order_id="<?php echo $order_row->id; ?>">
              <div class="wd_shop_panel_product panel panel-default">
                  <div class="panel-body">
                    <div class="row">
                      <div class="col-sm-3">
                        <div class="row">
                          <?php
                          // show big image if there is one product or 4 small images
                          if (count($order_row->product_images) > 1) {
                            $class_img_container_col = 'col-xs-6';
                            $class_img_container_single = '';
                          }
                          else {
                            $class_img_container_col = 'col-xs-12';
                            $class_img_container_single = 'wd_shop_order_product_image_container_single';
                          }
                          // images
                          $images_count_to_show = count($order_row->product_images) > 4 ? 3 : 4;
                          for ($j = 0; $j < min(count($order_row->product_images), $images_count_to_show); $j++) {
                            $product_image = $order_row->product_images[$j];
                            ?>
                            <div class="<?php echo $class_img_container_col; ?>">
                              <div class="wd_shop_order_product_image_container <?php echo $class_img_container_single; ?> wd_center_wrapper">
                                <div>
                                  <?php
                                  if ($product_image != '') {
                                    ?>
                                  <img class="wd_shop_order_product_image" src="<?php echo $product_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>
                            <?php
                          }
                          // add ... image if there is more than 4 images
                          if (count($order_row->product_images) > 4) {
                            $product_image = $order_row->product_images[$j];
                            ?>
                            <div class="wd_shop_order_product_image_container <?php echo $class_img_container_col; ?> wd_center_wrapper">
                              <div>
                                <div class="wd_shop_order_product_image_more">
                                  <span>...</span>
                                </div>
                              </div>
                            </div>
                            <?php
                          }
                          ?>
                        </div>
                      </div>
                      <div class="col-sm-6">
                        <a href="<?php echo $order_row->order_link; ?>"
                           class="wd_shop_order_btn_product_names wd_shop_product_name_all btn btn-link">
                          <?php echo $order_row->product_names; ?>
                          <small>(<?php echo __('Order ID', 'wde') . ': ' . $order_row->id; ?>)</small>
                        </a>
                        <p>
                          <small>
                            <?php _e('Checkout date', 'wde'); ?>:
                          </small>
                          <small>
                            <?php echo date($options->option_date_format, strtotime($order_row->checkout_date)); ?>
                          </small>
                          <br />
                          <small>
                            <?php _e('Status', 'wde'); ?>:
                          </small>
                          <small>
                            <?php echo $order_row->status_name; ?>
                          </small>
                        </p>
                      </div>
                      <div class="col-sm-3 text-right">
                        <p class="wd_shop_order_price_container">
                          <span class="wd_shop_order_price_title wd_shop_product_price_all">
                            <?php _e('Price', 'wde'); ?>:
                          </span>
                          <br />
                          <span class="wd_shop_order_price wd_shop_product_price_all">
                            <?php echo $order_row->price_text; ?>
                          </span>
                        </p>
                        <?php
                        if ($order_row->tax_price > 0) {
                        ?>
                        <p class="wd_shop_order_tax_price_container">
                          <span class="wd_shop_order_price_title wd_shop_product_price_all">
                            <?php _e('Tax', 'wde'); ?>:
                          </span>
                          <br>
                          <span class="wd_shop_order_price wd_shop_product_price_all">
                            <?php echo $order_row->tax_price_text; ?>
                          </span>
                        </p>
                        <?php
                        }
                        if ($order_row->shipping_price > 0) {
                        ?>
                        <p>
                          <span class="wd_shop_order_price_title wd_shop_product_price_all">
                            <?php _e('Shipping', 'wde'); ?>:
                          </span>
                          <br />
                          <span class="wd_shop_order_price wd_shop_product_price_all">
                            <?php echo $order_row->shipping_price_text; ?>
                          </span>
                        </p>
                        <?php
                        }
                        ?>
                        <div class="wd_divider"></div>
                        <p>                                     
                          <span class="wd_shop_order_price_title wd_shop_product_price_all">
                            <?php _e("Total price", 'wde'); ?>:
                          </span>
                          <br />
                          <span class="wd_shop_order_price wd_shop_product_price_all">
                            <?php echo $order_row->total_price_text; ?>
                          </span>
                        </p>
                      </div>
                    </div>
                  </div>
                  <div class="panel-footer">
                    <div class="row">
                      <div class="col-sm-12 text-right">
                        <div class="wd_shop_order_ctrls">
                          <a class="btn btn-link btn-sm"
                             href="<?php echo $order_row->print_orders_link; ?>" target="_blank">
                            <?php _e('Print order', 'wde'); ?>
                          </a>
                          <?php
                          $where_query = array(" published ='1' AND name='ecommercewd_pdfinvoice'");
                          $tools = WDFTool::get_tools($where_query);
                          if (empty($tools) == FALSE) {
                            ?>
                          <a class="btn btn-link btn-sm"
                             href="<?php echo $order_row->pdf_invoice_link; ?>" >
                            <?php _e('PDF invoice', 'wde'); ?>
                          </a>											
                            <?php
                          }
                          ?>
                          <a class="btn btn-link btn-sm"
                             href="<?php echo $order_row->order_link; ?>" >
                            <?php _e('View order details', 'wde'); ?>
                          </a>
                        </div>
                      </div>
                    </div>
                  </div>
              </div>
          </div>
        <?php
      }
      ?>
    </div>
    <hr />
    <?php require WD_E_DIR . '/frontend/views/orders/tmpl/displayorders_barpagination.php'; ?>
  <?php
  }
  else {
    ?>
    <div class="row">
      <div class="col-sm-12">
        <div class="alert alert-info">
          <?php _e('No orders yet', 'wde') ?>
        </div>
      </div>
    </div>
    <?php
  }
  ?>
</div>