{% extends 'admin_frontend/base.html' %}
{% block title %}Introduction Requests{% endblock %}
{% block content %}
<div class="flex items-center justify-between mb-4">
  <h1 class="text-2xl font-semibold">Introduction Requests</h1>
  <a href="{% url 'admin_frontend:intro_request_create' %}" class="btn">New</a>
  </div>
<div class="bg-white rounded shadow overflow-hidden">
  <table class="min-w-full divide-y divide-gray-200">
    <thead class="bg-gray-50">
      <tr>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">From</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">To</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Message</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Status</th>
        <th class="px-4 py-2"></th>
      </tr>
    </thead>
    <tbody class="divide-y divide-gray-200">
      {% for r in requests %}
      <tr>
        <td class="px-4 py-2">{{ r.from_user.username }}</td>
        <td class="px-4 py-2">{{ r.to_user.username }}</td>
        <td class="px-4 py-2">{{ r.message }}</td>
        <td class="px-4 py-2">
          {% if r.is_accepted %}
            <span class="inline-flex items-center gap-1 text-green-700"><span class="w-2 h-2 bg-green-600 rounded-full"></span> Accepted</span>
          {% else %}
            <span class="text-gray-500">Pending</span>
          {% endif %}
        </td>
        <td class="px-4 py-2 text-right">
          <div class="flex gap-2 justify-end">
            {% if not r.is_accepted %}
              <form method="post" action="{% url 'admin_frontend:intro_request_accept' r.pk %}">
                {% csrf_token %}
                <button class="btn-outline">Accept</button>
              </form>
            {% endif %}
            <a class="btn-outline" href="{% url 'admin_frontend:intro_request_edit' r.pk %}">Edit</a>
            <form method="post" action="{% url 'admin_frontend:intro_request_delete' r.pk %}" onsubmit="return confirm('Delete this request?');">
              {% csrf_token %}
              <button class="btn-outline text-red-600">Delete</button>
            </form>
          </div>
        </td>
      </tr>
      {% empty %}
      <tr><td class="px-4 py-4 text-center text-gray-500" colspan="5">No introduction requests.</td></tr>
      {% endfor %}
    </tbody>
  </table>
  {% include 'admin_frontend/_pagination.html' %}
  </div>
{% endblock %}
