{% extends "group_admin/base.html" %}
{% block title %}Permissions – {{ member.username }}{% endblock %}
{% block content %}
<div class="d-flex align-items-center gap-2 mb-4">
    <a href="{{ url_for('group_admin.members') }}" class="btn btn-sm btn-outline-secondary">
        <i class="bi bi-arrow-left"></i>
    </a>
    <h2 class="mb-0">Permissions: <span class="text-warning">{{ member.username }}</span></h2>
</div>

<div class="row">
    <div class="col-md-7">
        <div class="card border-secondary">
            <div class="card-header">
                <i class="bi bi-shield-lock-fill me-2"></i>Panel Permissions
            </div>
            <div class="card-body">
                <form method="post">
                    <input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
                    <div class="mb-3">
                        <label class="form-label">Role</label>
                        <select name="role" class="form-select">
                            <option value="member" {{ 'selected' if member.role == 'member' }}>Member</option>
                            <option value="admin" {{ 'selected' if member.role == 'admin' }}>Admin</option>
                        </select>
                        <div class="form-text">Admins can manage members and the DB connection.</div>
                    </div>

                    <hr>
                    <p class="form-label mb-2">Panel Access</p>
                    <div class="row g-2">
                    {% for key, label in all_permissions %}
                    <div class="col-md-6">
                        <div class="form-check form-switch">
                            <input class="form-check-input" type="checkbox" role="switch"
                                   name="perm_{{ key }}" id="perm_{{ key }}"
                                {{ 'checked' if current_perms.get(key, True) }}>
                            <label class="form-check-label" for="perm_{{ key }}">{{ label }}</label>
                        </div>
                    </div>
                    {% endfor %}
                    </div>

                    <div class="d-flex gap-2 mt-4">
                        <button type="submit" class="btn btn-warning">
                            <i class="bi bi-check-lg me-1"></i>Save
                        </button>
                        <a href="{{ url_for('group_admin.members') }}" class="btn btn-outline-secondary">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
