{% extends "base.j2" -%}

{%- block call_to_action -%}
<a href="/s/{{ request.shop.uuid_str }}/gift-cards/manage" class="mps-button mps-button-small">All Gift Cards</a>
{%- endblock call_to_action -%}

{% block content -%}

<section class="one-column">
  <section class="well">
    <h2>Gift Card: {{ gift_card.code }}</h2>

    <table class="mps-table">
      <tr><td>Code</td><td><strong>{{ gift_card.code }}</strong></td></tr>
      <tr><td>Initial Amount</td><td>${{ '{:,.2f}'.format(gift_card.initial_amount) }}</td></tr>
      <tr><td>Balance</td><td>${{ '{:,.2f}'.format(gift_card.balance) }}</td></tr>
      <tr><td>Purchaser</td><td>{{ gift_card.purchaser_email or '-' }}</td></tr>
      <tr><td>Recipient</td><td>{{ gift_card.gift_email or '-' }}</td></tr>
      {% if gift_card.gift_message %}
      <tr><td>Message</td><td>{{ gift_card.gift_message }}</td></tr>
      {% endif %}
      <tr><td>Status</td><td>
        {% if gift_card.disabled %}
          <span class="badge-error">Disabled</span>
        {% elif gift_card.is_fully_redeemed %}
          <span class="badge-info">Fully Redeemed</span>
        {% else %}
          <span class="badge-success">Active</span>
        {% endif %}
      </td></tr>
    </table>

    <br/>

    <form method="POST" action="/s/{{ request.shop.uuid_str }}/gift-cards/{{ gift_card.uuid_str }}/toggle">
      {% include "snippets/csrf.j2" %}
      <button type="submit" class="mps-button mps-button-small">
        {{ "Enable" if gift_card.disabled else "Disable" }} Gift Card
      </button>
    </form>
  </section>

  <br/>

  <section class="well">
    <h3>Transaction History</h3>
    {% if transactions %}
    <table class="mps-table">
      <thead>
        <tr>
          <th>Date</th>
          <th>Amount</th>
          <th>Invoice</th>
        </tr>
      </thead>
      <tbody>
      {% for txn in transactions %}
        <tr>
          <td>{{ txn.created_timestamp }}</td>
          <td>-${{ '{:,.2f}'.format(txn.amount) }}</td>
          <td><a href="/invoice/{{ txn.invoice.uuid_str }}">{{ txn.invoice.uuid_str[:8] }}...</a></td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
    {% else %}
    <p>No transactions yet.</p>
    {% endif %}
  </section>
</section>

{%- endblock -%}
