{% extends 'base.html' %}

{% block title %}Gebruikersbeheer - Digitale Liturgie{% endblock %}

{% block content %}

<div class="space-y-8 max-w-6xl mx-auto px-4">

  <h2 class="text-3xl font-semibold mb-6">Gebruikersbeheer</h2>

  <div class="overflow-x-auto rounded-lg border border-gray-300">
    <table class="min-w-full divide-y divide-gray-200 bg-white">
      <thead class="bg-gray-100">
        <tr>
          <th scope="col" class="px-6 py-3 text-left text-sm font-semibold text-gray-700">Gebruikersnaam</th>
          <th scope="col" class="px-6 py-3 text-sm font-semibold text-gray-700">Kerk</th>
          <th scope="col" class="px-6 py-3 text-sm font-semibold text-gray-700">Admin</th>
          <th scope="col" class="px-6 py-3 text-center text-sm font-semibold text-gray-700">Impersonalisatie</th>
          <th scope="col" class="px-6 py-3 text-center text-sm font-semibold text-gray-700">Acties</th>
        </tr>
      </thead>
      <tbody class="divide-y divide-gray-200">
        {% for user in users %}
        <tr>
          <td class="whitespace-nowrap px-6 py-4 text-sm text-gray-900">{{ user.username }}</td>
          <td class="px-6 py-4 text-sm text-gray-900">{{ user.church.name }}</td>
          <td class="px-6 py-4 text-sm text-gray-900">{% if user.is_admin %}Ja{% else %}Nee{% endif %}</td>
          <td class="text-center px-6 py-4">
            {% if not user.is_admin %}
            <a href="{{ url_for('admin_impersonate', user_id=user.id) }}" class="bg-[#f7d91a] text-black text-xs px-6 py-3 rounded font-semibold hover:bg-yellow-300 transition">Impersonate</a>
            {% else %}-{% endif %}
          </td>
          <td class="text-center px-6 py-4">
            {% if not user.is_admin %}
            <form action="{{ url_for('admin_delete_user', user_id=user.id) }}" method="post" style="display:inline;" onsubmit="return confirm('Weet je zeker dat je deze gebruiker en alle bijbehorende kerkdata wilt verwijderen?');">
              <button type="submit" class="bg-red-600 text-white text-xs px-6 py-3 rounded font-semibold hover:bg-red-700 transition">Verwijderen</button>
            </form>
            {% else %}-{% endif %}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>

  <a href="{{ url_for('admin_dashboard') }}" class="bg-white text-black border border-black px-6 py-3 rounded-md font-semibold shadow hover:bg-gray-100 transition inline-block mt-6">Terug naar dashboard</a>

</div>

{% endblock %}