{% extends "base.html" %}
{% block title %}Delete {{ role.name }} — Fossilrepo{% endblock %}

{% block content %}
<div class="mb-6">
  <a href="{% url 'organization:role_detail' slug=role.slug %}" class="text-sm text-brand-light hover:text-brand">&larr; Back to {{ role.name }}</a>
</div>

<div class="mx-auto max-w-lg">
  <div class="rounded-lg bg-gray-800 p-6 shadow border border-gray-700">
    <h2 class="text-lg font-semibold text-gray-100">Delete Role</h2>

    {% if active_members.exists %}
    <div class="mt-4 rounded-md bg-yellow-900/50 border border-yellow-700 p-4">
      <p class="text-sm text-yellow-300">
        This role has <strong>{{ active_members.count }}</strong> active member{{ active_members.count|pluralize }}.
        You must reassign them to another role before deleting.
      </p>
      <ul class="mt-2 text-sm text-yellow-300 list-disc list-inside">
        {% for membership in active_members %}
        <li>{{ membership.member.username }}</li>
        {% endfor %}
      </ul>
    </div>
    <div class="mt-6 flex justify-end">
      <a href="{% url 'organization:role_detail' slug=role.slug %}"
         class="rounded-md bg-gray-700 px-4 py-2 text-sm font-semibold text-gray-100 shadow-sm ring-1 ring-inset ring-gray-600 hover:bg-gray-600">
        Go Back
      </a>
    </div>
    {% else %}
    <p class="mt-2 text-sm text-gray-400">
      Are you sure you want to delete <strong class="text-gray-100">{{ role.name }}</strong>? This action uses soft delete -- the record will be marked as deleted but can be recovered.
    </p>
    <form method="post" class="mt-6 flex justify-end gap-3">
      {% csrf_token %}
      <a href="{% url 'organization:role_detail' slug=role.slug %}"
         class="rounded-md bg-gray-700 px-4 py-2 text-sm font-semibold text-gray-100 shadow-sm ring-1 ring-inset ring-gray-600 hover:bg-gray-600">
        Cancel
      </a>
      <button type="submit"
              class="rounded-md bg-red-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-500">
        Delete
      </button>
    </form>
    {% endif %}
  </div>
</div>
{% endblock %}
