{% extends "group_admin/base.html" %}
{% block title %}Members{% endblock %}
{% block content %}
<h2 class="mb-4"><i class="bi bi-people-fill me-2"></i>Members</h2>

<div class="row g-3">
    <!-- Mitgliederliste -->
    <div class="col-md-8">
        <div class="card border-secondary">
            <div class="card-header">Current Members ({{ members|length }})</div>
            <div class="card-body p-0">
                <table class="table table-hover mb-0">
                    <thead><tr><th>User</th><th>Role</th><th class="text-end">Actions</th></tr></thead>
                    <tbody>
                    {% for m in members %}
                    <tr>
                        <td>{{ m.username }}</td>
                        <td>
                            {% if m.role == 'admin' %}
                            <span class="badge bg-warning text-dark"><i class="bi bi-star-fill me-1"></i>Admin</span>
                            {% else %}
                            <span class="badge bg-secondary">Member</span>
                            {% endif %}
                        </td>
                        <td class="text-end">
                            {% if m.id != session.get('user_id') %}
                            <a href="{{ url_for('group_admin.member_edit', user_id=m.id) }}" class="btn btn-sm btn-outline-warning" title="Permissions">
                                <i class="bi bi-shield-lock"></i>
                            </a>
                            <form method="post" action="{{ url_for('group_admin.member_remove', user_id=m.id) }}" class="d-inline"
                                  onsubmit="return confirm('Remove {{ m.username }}?')">
                                <input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
                                <button type="submit" class="btn btn-sm btn-outline-danger" title="Remove">
                                    <i class="bi bi-person-dash"></i>
                                </button>
                            </form>
                            {% else %}
                            <span class="text-muted small">You</span>
                            {% endif %}
                        </td>
                    </tr>
                    {% else %}
                    <tr><td colspan="3" class="text-muted text-center py-3">No members</td></tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Member invitation note: only Site Admin can add new users to groups -->
    <div class="col-md-4">
        <div class="card border-secondary">
            <div class="card-header"><i class="bi bi-info-circle me-2"></i>Note</div>
            <div class="card-body">
                <p class="text-muted small">
                    New members must be added by the <strong>Site Admin</strong>.
                </p>
                <p class="text-muted small">
                    As group admin you can manage permissions of existing members and remove members.
                </p>
            </div>
        </div>
    </div>
</div>
{% endblock %}
