{% extends "base.j2" -%}

{%- block call_to_action -%}
<a href="/s/{{ request.shop.uuid_str }}/settings" class="mps-button mps-button-small">Settings</a>
{%- endblock call_to_action -%}

{% block content -%}

<section class="one-column">
  <section class="well">
    <h2>Gift Cards</h2>
    <p>
      Total issued: <strong>${{ '{:,.2f}'.format(total_issued_dollars) }}</strong> |
      Outstanding balance: <strong>${{ '{:,.2f}'.format(total_balance_dollars) }}</strong>
    </p>
  </section>

  <br/>

  {% if gift_cards %}
  <section class="well">
    <table class="mps-table">
      <thead>
        <tr>
          <th>Code</th>
          <th>Amount</th>
          <th>Balance</th>
          <th>Recipient</th>
          <th>Status</th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody>
      {% for gc in gift_cards %}
        <tr>
          <td><a href="/s/{{ request.shop.uuid_str }}/gift-cards/{{ gc.uuid_str }}">{{ gc.code }}</a></td>
          <td>${{ '{:,.2f}'.format(gc.initial_amount) }}</td>
          <td>${{ '{:,.2f}'.format(gc.balance) }}</td>
          <td>{{ gc.gift_email or gc.purchaser_email or '-' }}</td>
          <td>
            {% if gc.disabled %}
              <span class="badge-error">Disabled</span>
            {% elif gc.is_fully_redeemed %}
              <span class="badge-info">Redeemed</span>
            {% else %}
              <span class="badge-success">Active</span>
            {% endif %}
          </td>
          <td>
            <form method="POST" action="/s/{{ request.shop.uuid_str }}/gift-cards/{{ gc.uuid_str }}/toggle" style="display:inline;">
              {% include "snippets/csrf.j2" %}
              <button type="submit" class="mps-button mps-button-small">
                {{ "Enable" if gc.disabled else "Disable" }}
              </button>
            </form>
          </td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
  </section>
  {% else %}
  <section class="well">
    <p>No gift cards issued yet.</p>
  </section>
  {% endif %}
</section>

{%- endblock -%}
