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

<section class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1>Customer Dashboard</h1>
      </div>
    </div>
  </div>
</section>

<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-4">
        <div class="small-box bg-success">
          <div class="inner">
            <h3><?php echo esc($balance) ?></h3>
            <p>Reward Points Balance</p>
          </div>
          <div class="icon">
            <i class="fas fa-star"></i>
          </div>
          <a href="<?php echo url('user/wallet') ?>" class="small-box-footer">View wallet <i class="fas fa-arrow-circle-right"></i></a>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-md-7">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">Latest Discounts</h3>
            <div class="card-tools">
              <a href="<?php echo url('user/discounts') ?>" class="btn btn-sm btn-default">View all</a>
            </div>
          </div>
          <div class="card-body">
            <table class="table table-bordered table-sm">
              <thead>
                <tr>
                  <th>Shop</th>
                  <th>Applies</th>
                  <th width="140">Value</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach ($discounts as $d): ?>
                  <tr>
                    <td><?php echo esc($d->shop_name) ?></td>
                    <td><?php echo esc($d->applies_to) ?></td>
                    <td><?php echo esc($d->discount_type) ?> <?php echo esc($d->value) ?></td>
                  </tr>
                <?php endforeach ?>
                <?php if (empty($discounts)): ?>
                  <tr><td colspan="3" class="text-muted">No discounts</td></tr>
                <?php endif ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>

      <div class="col-md-5">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">Recent Orders</h3>
            <div class="card-tools">
              <a href="<?php echo url('user/orders') ?>" class="btn btn-sm btn-default">View all</a>
            </div>
          </div>
          <div class="card-body">
            <table class="table table-bordered table-sm">
              <thead>
                <tr>
                  <th width="70">#</th>
                  <th>Shop</th>
                  <th width="90">Total</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach ($orders as $o): ?>
                  <tr>
                    <td><?php echo $o->id ?></td>
                    <td><?php echo esc($o->shop_name) ?></td>
                    <td><?php echo esc($o->total) ?></td>
                  </tr>
                <?php endforeach ?>
                <?php if (empty($orders)): ?>
                  <tr><td colspan="3" class="text-muted">No orders</td></tr>
                <?php endif ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

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

