{% extends "admin/base_admin.html" %}

{% block title %}Members Management - Admin Panel{% endblock %}

{% block page_title %}All Members{% endblock %}

{% block content %}
<!-- Members Management -->
<div class="p-8">
    <div class="flex justify-between items-center mb-8">
        <div>
            <h3 class="text-2xl font-bold text-gray-900 mb-2">
                Members Management
            </h3>
            <p class="text-gray-600">
                View and manage all group members and their account details
            </p>
        </div>
        <a href="{{ url_for('admin_add_member') }}" class="inline-flex items-center px-6 py-3 border border-transparent text-sm font-medium rounded-xl text-white bg-gradient-to-r from-blue-500 to-purple-500 hover:from-blue-600 hover:to-purple-600 shadow-lg shadow-blue-500/25 transition-all duration-200">
            <i class="fas fa-plus mr-2"></i>Add Member
        </a>
    </div>

        <div class="bg-white dark:bg-gray-800 shadow overflow-hidden sm:rounded-md">
            <ul role="list" class="divide-y divide-gray-200 dark:divide-gray-700">
                {% for member in members %}
                <li class="px-6 py-4">
                    <div class="flex items-center justify-between">
                        <div class="flex items-center">
                            <div class="flex-shrink-0 h-12 w-12">
                                <div class="h-12 w-12 rounded-full bg-primary-100 dark:bg-primary-900 flex items-center justify-center">
                                    {% if member.is_admin %}
                                        <i class="fas fa-user-shield text-primary-600 dark:text-primary-400"></i>
                                    {% else %}
                                        <i class="fas fa-user text-primary-600 dark:text-primary-400"></i>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="ml-4">
                                <div class="text-sm font-medium text-gray-900 dark:text-white">
                                    {% if member.custom_id %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 mr-2">{{ member.custom_id }}</span>
                                    {% endif %}
                                    {{ member.full_name }}
                                    {% if member.is_admin %}
                                        <span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">Admin</span>
                                    {% endif %}
                                </div>
                                <div class="text-sm text-gray-500 dark:text-gray-400">
                                    @{{ member.username }}{% if member.custom_id %} ({{ member.custom_id }}){% endif %} • {{ member.email }}
                                </div>
                                {% if member.phone_number %}
                                <div class="text-sm text-gray-500 dark:text-gray-400">
                                    <i class="fas fa-phone mr-1"></i>{{ member.phone_number }}
                                </div>
                                {% endif %}
                            </div>
                        </div>
                        <div class="flex items-center space-x-3">
                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium 
                                {% if member.is_active %}bg-green-100 text-green-800{% else %}bg-red-100 text-red-800{% endif %}">
                                {% if member.is_active %}Active{% else %}Inactive{% endif %}
                            </span>
                            <div class="text-sm text-gray-500 dark:text-gray-400">
                                Joined {{ member.join_date.strftime('%b %d, %Y') if member.join_date else 'Unknown' }}
                            </div>
                            
                            <!-- Action Buttons -->
                            <div class="flex items-center space-x-2">
                                <a href="{{ url_for('admin_edit_member', member_id=member.id) }}" 
                                   class="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300"
                                   title="Edit Member">
                                    <i class="fas fa-edit"></i>
                                </a>
                                {% if not member.is_admin %}
                                <form method="POST" action="{{ url_for('admin_delete_member', member_id=member.id) }}" 
                                      class="inline" onsubmit="return confirm('Are you sure you want to delete this member?')">
                                    <button type="submit" 
                                            class="text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300"
                                            title="Delete Member">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </form>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                </li>
                {% else %}
                <li class="px-6 py-8">
                    <div class="text-center">
                        <i class="fas fa-users text-4xl text-gray-300 dark:text-gray-600 mb-4"></i>
                        <p class="text-sm text-gray-500 dark:text-gray-400 mb-4">No members found.</p>
                        <a href="{{ url_for('admin_add_member') }}" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-primary-600 hover:bg-primary-700">
                            <i class="fas fa-plus mr-2"></i>Add First Member
                        </a>
                    </div>
                </li>
                {% endfor %}
            </ul>
        </div>
    </div>
</div>
{% endblock %}