<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>2FA Recovery Codes – Purge Report</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <!-- Keep styles in the same HTML for email -->
  <style>
    /* Client-safe resets */
    body, table, td, a { text-size-adjust: 100%; }
    table, td { border-collapse: collapse !important; }
    img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; }
    body { margin: 0 !important; padding: 0 !important; width: 100% !important; background: #f6f7f9; }

    /* Container */
    .wrapper { width: 100%; background: #f6f7f9; padding: 24px 0; }
    .container { max-width: 680px; margin: 0 auto; background: #ffffff; border-radius: 8px; overflow: hidden; border: 1px solid #e9edf3; }

    /* Header */
    .header { background: #0f172a; color: #ffffff; padding: 20px 24px; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
    .title { margin: 0; font-size: 18px; line-height: 1.4; }
    .subtitle { margin: 4px 0 0 0; font-size: 13px; opacity: 0.9; }

    /* Body */
    .content { padding: 16px 24px 24px 24px; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; color: #0f172a; }
    .intro { font-size: 14px; line-height: 1.6; margin: 0 0 16px 0; }

    /* Card for each batch */
    .card { border: 1px solid #e9edf3; border-radius: 8px; margin: 16px 0; overflow: hidden; }
    .card-header { background: #f8fafc; padding: 12px 16px; font-weight: 600; font-size: 14px; border-bottom: 1px solid #e9edf3; }
    .kv { width: 100%; }
    .kv th, .kv td { text-align: left; vertical-align: top; padding: 10px 12px; font-size: 13px; }
    .kv th { width: 38%; background: #fbfdff; color: #334155; border-right: 1px solid #eef2f7; }
    .kv td { color: #0f172a; }
    .muted { color: #64748b; }

    /* Footer */
    .footer { padding: 16px 24px 24px 24px; color: #64748b; font-size: 12px; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }

    /* Badges */
    .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; line-height: 1.6; }
    .badge-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
    .badge-warn { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
  </style>
</head>
<body>
  <table role="presentation" class="wrapper" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td align="center">
        <table role="presentation" class="container" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td class="header">
              <h1 class="title">2FA Recovery Codes – Purge Report</h1>
              <p class="subtitle">
                Automated summary generated after Django Q completed the purge task.
              </p>
            </td>
          </tr>

          <tr>
            <td class="content">
              <p class="intro">
                Hello Admin,<br />
                Please find the details for the latest purge operation below.
              </p>

              {% if reports %}

                The total batches removed:  {{ total_batches_removed }}

                <br>
                
                {% for report in reports %}
                  <table role="presentation" width="100%" class="card" cellpadding="0" cellspacing="0" border="0">
                    <tr>
                      <td class="card-header">
                        Batch #{{ report.id }} —
                        {% if report.is_batch_empty %}
                          <span class="badge badge-ok">Batch is now empty</span>
                        {% else %}
                          <span class="badge badge-warn">Batch not empty</span>
                        {% endif %}
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <table role="presentation" class="kv" cellpadding="0" cellspacing="0" border="0">
                          <tr>
                            <th scope="row">Batch ID</th>
                            <td>{{ report.id }}</td>
                          </tr>
                          <tr>
                            <th scope="row">User Issued To</th>
                            <td>{{ report.user_issued_to  |title }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Number Issued</th>
                            <td>{{ report.number_issued }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Number Removed (Purged)</th>
                            <td>{{ report.number_removed }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Number Used</th>
                            <td>{{ report.number_used }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Number Remaining in Batch</th>
                            <td>{{ report.number_remaining_in_batch }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Was Codes Generated</th>
                            <td>{{ report.was_code_generated|yesno:"Yes,No,Unknown" }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Were Codes Downloaded</th>
                            <td>{{ report.was_codes_downloaded|yesno:"Yes,No,Unknown" }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Were Codes Viewed</th>
                            <td>{{ report.was_codes_viewed|yesno:"Yes,No,Unknown" }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Were Codes Emailed</th>
                            <td>{{ report.was_codes_emailed|yesno:"Yes,No,Unknown" }}</td>
                          </tr>
                          <tr>
                            <th scope="row">Batch Creation Date</th>
                            <td>
                              {% if report.batch_creation_date %}
                                {{ report.batch_creation_date|date:"Y-m-d H:i:s T" }}
                              {% else %}<span class="muted">N/A</span>{% endif %}
                            </td>
                          </tr>
                          <tr>
                            <th scope="row">Last Modified</th>
                            <td>
                              {% if report.last_modified %}
                                {{ report.last_modified|date:"Y-m-d H:i:s T" }}
                              {% else %}<span class="muted">N/A</span>{% endif %}
                            </td>
                          </tr>
                          <tr>
                            <th scope="row">Expiry Date</th>
                            <td>
                              {% if report.expiry_date %}
                                {{ report.expiry_date|date:"Y-m-d H:i:s T" }}
                              {% else %}<span class="muted">N/A</span>{% endif %}
                            </td>
                          </tr>
                          <tr>
                            <th scope="row">Deleted At</th>
                            <td>
                              {% if report.deleted_at %}
                                {{ report.deleted_at|date:"Y-m-d H:i:s T" }}
                              {% else %}<span class="muted">N/A</span>{% endif %}
                            </td>
                          </tr>
                          <tr>
                            <th scope="row">Deleted By</th>
                            <td>
                              {% if report.deleted_by %}
                               
                                {{ report.deleted_by.username|default:"N/A" | title }}
                              {% else %}
                                <span class="muted">N/A</span>
                              {% endif %}
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                {% endfor %}
              {% else %}
                <p class="muted">No purge reports were generated.</p>
              {% endif %}
            </td>
          </tr>

          <tr>
            <td class="footer">
              This is an automated message from the security system. If you believe you received this in error,
              please contact the operations team.
              <br /><br />
              <span class="muted">Environment:</span> {{ environment|default:"production" }} &nbsp;•&nbsp;
              <span class="muted">Generated:</span> {{ now|date:"Y-m-d H:i:s T" }}
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>
