<?= $this->extend('admin/layout/default') ?>
<?= $this->section('content') ?>

<section class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1>Order #<?php echo $order->id ?></h1>
      </div>
      <div class="col-sm-6 text-right">
        <a class="btn btn-default btn-sm" href="<?php echo url('rewarderOrders') ?>">Back</a>
      </div>
    </div>
  </div>
</section>

<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-4">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">Customer</h3>
          </div>
          <div class="card-body">
            <div><strong><?php echo esc($order->customer_name) ?></strong></div>
            <div class="text-muted"><?php echo esc($order->customer_username ?? $order->customer_email) ?></div>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">Shop</h3>
          </div>
          <div class="card-body">
            <div><strong><?php echo esc($order->shop_name) ?></strong></div>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">Summary</h3>
          </div>
          <div class="card-body">
            <div class="row">
              <div class="col-6"><strong>Subtotal</strong><div><?php echo esc($order->subtotal) ?></div></div>
              <div class="col-6"><strong>Discount</strong><div><?php echo esc($order->discount_total) ?></div></div>
            </div>
            <div class="row mt-2">
              <div class="col-6"><strong>Total</strong><div><?php echo esc($order->total) ?></div></div>
              <div class="col-6"><strong>Points</strong><div><?php echo esc($order->points_earned) ?></div></div>
            </div>
            <div class="mt-2 text-muted"><?php echo esc($order->created_at) ?></div>
          </div>
        </div>
      </div>
    </div>

    <div class="card">
      <div class="card-header">
        <h3 class="card-title">Items</h3>
      </div>
      <div class="card-body">
        <table class="table table-bordered">
          <thead>
            <tr>
              <th>Type</th>
              <th>Name</th>
              <th width="80">Qty</th>
              <th width="120">Unit</th>
              <th width="120">Discount</th>
              <th width="120">Total</th>
              <th width="100">Points</th>
            </tr>
          </thead>
          <tbody>
            <?php foreach ($items as $it): ?>
              <tr>
                <td><?php echo esc($it->item_type) ?></td>
                <td><?php echo esc($it->name) ?></td>
                <td><?php echo esc($it->quantity) ?></td>
                <td><?php echo esc($it->unit_price) ?></td>
                <td><?php echo esc($it->discount_amount) ?></td>
                <td><?php echo esc($it->line_total) ?></td>
                <td><?php echo esc($it->points_earned) ?></td>
              </tr>
            <?php endforeach ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</section>

<?= $this->endSection() ?>

