<?php

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

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

$options = $this->options;

$order_row = $this->order_row;
?>
<div class="container">
  <h1 class="wd_shop_header">
    <?php _e('Order', 'wde'); ?>
  </h1>
  <div class="row">
    <div class="col-sm-12">
      <?php require WD_E_DIR . '/frontend/views/products/tmpl/displayproducts_bartop.php'; ?>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-12">
        <h4 class="wd_shop_order_id">
          <?php echo __('Order ID', 'wde') . ': ' . $order_row->id; ?>
        </h4>
        <p class="wd_shop_order_checkout_date">
          <small><?php echo __('Checkout date', 'wde') . ': ' . date($options->option_date_format, strtotime($order_row->checkout_date)); ?></small>
        </p>
        <div class="wd_divider"></div>
        <?php
        for ($i = 0; $i < count($order_row->product_rows); $i++) {
            $order_product_row = $order_row->product_rows[$i];
            ?>
            <div class="row">
                <div class="col-sm-3">
                    <div class="wd_shop_order_product_image_container wd_center_wrapper">
                        <div>
                            <?php
                            if ($order_product_row->image != '') {
                                ?>
                                <img class="wd_shop_order_product_image"
                                     src="<?php echo $order_product_row->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>

                <!-- details -->
                <div class="col-sm-6">
                    <h4 class="wd_shop_order_product_name wd_shop_product_name text-left">
                        <!-- product name -->
                        <?php echo $order_product_row->name; ?>

                        <!-- product id -->
                        <small>
                            (<?php echo __('Product ID', 'wde') . ': ' . $order_product_row->id; ?>)
                        </small>
                    </h4>

                    <!-- shipping method name -->
                    <?php
                    if ($order_product_row->enable_shipping == 1) {
                        ?>
                        <p class="wd_shop_order_product_shipping_method_name">
                            <?php echo __('Shipping', 'wde') . ': ' . $order_product_row->shipping_method_name; ?>
                        </p>
                    <?php
                    }
                    ?>

                    <!-- parameters -->
                    <p class="wd_shop_order_product_parameters">
                        <?php echo __('Parameters', 'wde') . ': ' . $order_product_row->parameters; ?>
                    </p>
                </div>

                <div class="col-sm-3 text-right">
                    <!-- price -->
                    <p>
                        <span class="wd_shop_order_product_price_title wd_shop_product_price">
                            <?php _e('Price', 'wde'); ?>:
                        </span>
                        <br>
                        <span class="wd_shop_order_product_price wd_shop_product_price">
                            <?php echo $order_product_row->price_text; ?>
                        </span>
                    </p>
                    <?php
                    if ($order_product_row->tax_price > 0) {
                    ?>
                      <!-- tax price -->
                      <p>
                        <span class="wd_shop_order_product_price_title wd_shop_product_price">
                            <?php _e('Tax', 'wde'); ?>:
                        </span>
                        <br>
                        <span class="wd_shop_order_product_price wd_shop_product_price">
                            <?php echo $order_product_row->tax_price_text; ?>
                        </span>
                      </p>
                    <?php
                    }
                    ?>
                    <!-- count -->
                    <p>
                            <span class="wd_shop_order_product_price_title wd_shop_product_price">
                                <?php echo __('Quantity', 'wde') . ': ' . $order_product_row->count; ?>
                            </span>
                    </p>
                </div>
            </div>
        <?php
        if ($order_product_row->shipping_method_price > 0) {
        ?>
        <div class="row">
          <div class="text-right col-sm-12">
            <!-- shipping price -->
            <span class="wd_shop_order_product_shipping_price_title">
              <?php _e('Shipping', 'wde'); ?>:
            </span>
            <span class="wd_shop_order_product_shipping_price">
              <?php echo $order_product_row->shipping_method_price_text; ?>
            </span>
          </div>
        </div>
        <?php
        }
        ?>
            <div class="wd_divider"></div>
        <?php
        }
    if ($order_row->shipping_method_price > 0) {
    ?>
      <div class="row">
        <div class="text-right col-sm-12">
          <!-- shipping price -->
          <span class="wd_shop_order_product_shipping_price_title">
            <?php _e('Shipping', 'wde'); ?>:
          </span>
          <span class="wd_shop_order_product_shipping_price">
            <?php echo $order_row->shipping_method_price_text; ?>
          </span>
        </div>
      </div>
      <div class="wd_divider"></div>
    <?php
    }
    ?>
</div>
</div>
  <div class="row">
    <div>
      <div>
        <div class="col-sm-6">
          <h4 class="wd_shop_header_sm">
            <?php _e('Billing info', 'wde'); ?>
          </h4>

          <dl class="wd_shop_order_product_shipiing_info_data dl-horizontal">
            <?php
            if ($order_row->billing_data_first_name) {
            ?>
              <dt>
                <?php
                  if ($order_row->billing_data_middle_name || $order_row->billing_data_last_name) {
                    _e('First name', 'wde');
                  }
                  else {
                    _e('Name', 'wde');
                  }
                ?>:
              </dt>
              <dd>
                <?php echo str_replace("'", "", $order_row->billing_data_first_name); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_middle_name) {
            ?>
              <dt>
                <?php _e('Middle name', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_middle_name); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_last_name) {
            ?>
              <dt>
                <?php _e('Last name', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_last_name); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_company) {
            ?>
              <dt>
                <?php _e('Company', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_company); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_email) {
            ?>
              <dt>
                <?php _e('Email', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_email); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_country) {
            ?>
              <dt>
                <?php _e('Country', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_country); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_state) {
            ?>
              <dt>
                <?php _e('State', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_state); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_city) {
            ?>
              <dt>
                <?php _e('City', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_city); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_address) {
            ?>
              <dt>
                <?php _e('Address', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_address); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_mobile) {
            ?>
              <dt>
                <?php _e('Mobile', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_mobile); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_phone) {
            ?>
              <dt>
                <?php _e('Phone', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_phone); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_fax) {
            ?>
              <dt>
                <?php _e('Fax', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_fax); ?>
              </dd>
            <?php
            }
            if ($order_row->billing_data_zip_code) {
            ?>
              <dt>
                <?php _e('Zip code', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->billing_data_zip_code); ?>
              </dd>
            <?php
            }
            ?>
          </dl>		
        </div>
        <div class="col-sm-6">
          <h4 class="wd_shop_header_sm">
            <?php _e('Shipping info', 'wde'); ?>
          </h4>

          <dl class="wd_shop_order_product_shipiing_info_data dl-horizontal">
            <?php
            if ($order_row->shipping_data_first_name) {
            ?>
              <dt>
                <?php
                  if ($order_row->shipping_data_middle_name || $order_row->shipping_data_last_name) {
                    _e('First name', 'wde');
                  }
                  else {
                    _e('Name', 'wde');
                  }
                ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_first_name); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_middle_name) {
            ?>
              <dt>
                <?php _e('Middle name', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_middle_name); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_last_name) {
            ?>
              <dt>
                <?php _e('Last name', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_last_name); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_company) {
            ?>
              <dt>
                <?php _e('Company', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_company); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_country) {
            ?>
              <dt>
                <?php _e('Country', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_country); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_state) {
            ?>
              <dt>
                <?php _e('State', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_state); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_city) {
            ?>
              <dt>
                <?php _e('City', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_city); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_address) {
            ?>
              <dt>
                <?php _e('Address', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_address); ?>
              </dd>
            <?php
            }
            if ($order_row->shipping_data_zip_code) {
            ?>
              <dt>
                <?php _e('Zip code', 'wde'); ?>:
              </dt>
              <dd>
                <?php echo str_replace("'","",$order_row->shipping_data_zip_code); ?>
              </dd>
            <?php
            }
            ?>
          </dl>
        </div>
      </div>
    </div>
  </div>
<div class="wd_divider"></div>
  <div class="row">
    <div class="col-sm-4">
      <span class="wd_shop_order_status_title">
        <?php _e('Status', 'wde'); ?>:
      </span>
      <span class="wd_shop_order_status">
        <?php echo $order_row->status_name; ?>
      </span>
    </div>
    <div class="col-sm-8 text-right">
      <span class="wd_shop_order_price_title wd_shop_product_price">
        <?php _e('Total price', 'wde'); ?>:
      </span>
      <span class="wd_shop_order_price wd_shop_product_price">
        <?php echo $order_row->total_price_text; ?>
      </span>
    </div>
  </div>
  <div class="wd_divider"></div>
  <div class="row">
    <div class="col-sm-12 text-right">
      <a class="btn btn-primary" href="<?php echo WDFPath::add_pretty_query_args(get_permalink($options->option_orders_page), $options->option_endpoint_orders_printorder, $order_row->id, TRUE);?>" 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-primary" href="" ><?php _e('PDF invoice', 'wde') ?></a>
        <?php
      }
      ?>        
      <a class="btn btn-default" onclick="wdShop_onBtnBackClick(event, this); return false;"><?php _e('Back', 'wde') ?></a>
    </div>
  </div>
</div>