{% extends "base.html" %}
{% block title %}Password Resets{% endblock %}
{% block content %}
<div class="bbs-header"><h1><i class="bi bi-key"></i> Pending Password Resets</h1></div>

<p class="text-muted small">
  These are active, unused reset links. Copy the URL and send it to the user via
  any out-of-band channel (PM, chat, phone, etc.). Links expire after 24 hours or
  once used. Click <strong>Revoke</strong> to cancel a link early.
</p>

{% if tokens %}
<table class="table table-sm">
  <thead>
    <tr>
      <th>User</th>
      <th>Requested</th>
      <th>Expires</th>
      <th>From IP</th>
      <th>Reset URL</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
  {% for item in tokens %}
  <tr>
    <td><a href="{{ url_for('admin.edit_user', user_id=item.token.user_id) }}">{{ item.token.user.username }}</a></td>
    <td><small>{{ item.token.created_at|eastern('%Y-%m-%d %H:%M') }}</small></td>
    <td><small>{{ item.token.expires_at|eastern('%Y-%m-%d %H:%M') }}</small></td>
    <td><small>{{ item.token.requested_ip or '—' }}</small></td>
    <td>
      <div class="input-group input-group-sm">
        <input type="text" class="form-control form-control-sm font-monospace"
               value="{{ item.reset_url }}" readonly
               id="url-{{ item.token.id }}">
        <button class="btn btn-outline-secondary btn-sm"
                onclick="navigator.clipboard.writeText('{{ item.reset_url }}');this.textContent='Copied!';"
                title="Copy to clipboard">Copy</button>
      </div>
    </td>
    <td>
      <form method="post"
            action="{{ url_for('admin.revoke_reset_token', token_id=item.token.id) }}"
            onsubmit="return confirm('Revoke this reset link for {{ item.token.user.username }}?');">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <button class="btn btn-sm btn-outline-danger">Revoke</button>
      </form>
    </td>
  </tr>
  {% endfor %}
  </tbody>
</table>
{% else %}
<div class="alert alert-secondary">No pending password reset requests.</div>
{% endif %}
{% endblock %}
