{% extends "admin/base_admin.html" %}
{% from "admin/components/modern_card.html" import render_modern_card, render_action_button, render_status_badge %}

{% block title %}Enhanced Admin Dashboard{% endblock %}

{% block content %}
<div class="space-y-8">
    <!-- Enhanced Header Section -->
    <div class="bg-gradient-to-r from-blue-600 via-purple-600 to-indigo-700 rounded-3xl shadow-2xl overflow-hidden">
        <div class="px-8 py-12 relative">
            <!-- Background Pattern -->
            <div class="absolute inset-0 bg-black/10">
                <div class="absolute inset-0" style="background-image: radial-gradient(circle at 25% 25%, rgba(255,255,255,0.1) 0%, transparent 50%), radial-gradient(circle at 75% 75%, rgba(255,255,255,0.1) 0%, transparent 50%);"></div>
            </div>
            
            <div class="relative">
                <div class="flex flex-col lg:flex-row lg:items-center lg:justify-between">
                    <div class="mb-6 lg:mb-0">
                        <h1 class="text-4xl font-black text-white mb-3">
                            Welcome back, 
                            <span class="bg-gradient-to-r from-yellow-300 to-orange-300 bg-clip-text text-transparent">{{ current_user.full_name }}</span>
                        </h1>
                        <p class="text-xl text-blue-100 font-medium">{{ current_user.group.name if current_user.group else 'System Administrator' }}</p>
                        <div class="flex items-center space-x-4 mt-4">
                            <div class="flex items-center space-x-2">
                                <div class="w-3 h-3 bg-green-400 rounded-full animate-pulse"></div>
                                <span class="text-green-200 font-semibold text-sm">System Online</span>
                            </div>
                            <div class="text-blue-200 text-sm">
                                <i class="fas fa-calendar-alt mr-2"></i>
                                {{ moment().format('dddd, MMMM Do YYYY') if moment else now.strftime('%A, %B %d, %Y') }}
                            </div>
                        </div>
                    </div>
                    
                    <div class="flex flex-col sm:flex-row space-y-3 sm:space-y-0 sm:space-x-4">
                        {{ render_action_button("Add Member", "fas fa-user-plus", url_for('admin_add_member'), "green") }}
                        {{ render_action_button("Quick Reports", "fas fa-chart-bar", url_for('admin_reports'), "purple") }}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Enhanced Statistics Grid -->
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
        {{ render_modern_card("Total Members", "fas fa-users", members_count, "Active members in group", "blue", 12) }}
        {{ render_modern_card("Monthly Contributions", "fas fa-money-bill-wave", "৳" + "{:,.2f}".format(monthly_total), "This month", "green", 8) }}
        {{ render_modern_card("Pending Requests", "fas fa-clock", pending_requests, "Awaiting approval", "yellow", -5) }}
        {{ render_modern_card("Total Balance", "fas fa-piggy-bank", "৳" + "{:,.2f}".format(total_balance), "Group savings", "purple", 15) }}
    </div>

    <!-- Enhanced Quick Actions -->
    <div class="bg-white rounded-3xl shadow-xl border border-gray-100 overflow-hidden">
        <div class="bg-gradient-to-r from-gray-50 to-gray-100 px-8 py-6 border-b border-gray-200">
            <h2 class="text-2xl font-bold text-gray-900 flex items-center">
                <i class="fas fa-bolt text-yellow-500 mr-3"></i>
                Quick Actions
            </h2>
            <p class="text-gray-600 mt-1">Common administrative tasks</p>
        </div>
        
        <div class="p-8">
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <!-- Add Contribution -->
                <div class="group bg-gradient-to-br from-blue-50 to-indigo-100 rounded-2xl p-6 border border-blue-200 hover:shadow-lg transition-all duration-300 hover:-translate-y-1">
                    <div class="flex items-center space-x-4">
                        <div class="w-12 h-12 bg-gradient-to-br from-blue-500 to-indigo-600 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform duration-300">
                            <i class="fas fa-plus text-white"></i>
                        </div>
                        <div>
                            <h3 class="font-bold text-gray-900">Add Contribution</h3>
                            <p class="text-sm text-gray-600">Record new payment</p>
                        </div>
                    </div>
                    <div class="mt-4">
                        <a href="{{ url_for('admin_add_contribution') }}" class="inline-flex items-center text-blue-600 hover:text-blue-800 font-semibold text-sm">
                            Add Now <i class="fas fa-arrow-right ml-2"></i>
                        </a>
                    </div>
                </div>

                <!-- Bulk Import -->
                <div class="group bg-gradient-to-br from-green-50 to-emerald-100 rounded-2xl p-6 border border-green-200 hover:shadow-lg transition-all duration-300 hover:-translate-y-1">
                    <div class="flex items-center space-x-4">
                        <div class="w-12 h-12 bg-gradient-to-br from-green-500 to-emerald-600 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform duration-300">
                            <i class="fas fa-file-import text-white"></i>
                        </div>
                        <div>
                            <h3 class="font-bold text-gray-900">Bulk Import</h3>
                            <p class="text-sm text-gray-600">Import multiple records</p>
                        </div>
                    </div>
                    <div class="mt-4">
                        <a href="{{ url_for('admin_bulk_import') }}" class="inline-flex items-center text-green-600 hover:text-green-800 font-semibold text-sm">
                            Import Data <i class="fas fa-arrow-right ml-2"></i>
                        </a>
                    </div>
                </div>

                <!-- Create Event -->
                <div class="group bg-gradient-to-br from-purple-50 to-violet-100 rounded-2xl p-6 border border-purple-200 hover:shadow-lg transition-all duration-300 hover:-translate-y-1">
                    <div class="flex items-center space-x-4">
                        <div class="w-12 h-12 bg-gradient-to-br from-purple-500 to-violet-600 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform duration-300">
                            <i class="fas fa-calendar-plus text-white"></i>
                        </div>
                        <div>
                            <h3 class="font-bold text-gray-900">Create Event</h3>
                            <p class="text-sm text-gray-600">Special collection event</p>
                        </div>
                    </div>
                    <div class="mt-4">
                        <a href="{{ url_for('admin_create_event') }}" class="inline-flex items-center text-purple-600 hover:text-purple-800 font-semibold text-sm">
                            Create Event <i class="fas fa-arrow-right ml-2"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Enhanced Recent Activity & Payment Status -->
    <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
        <!-- Recent Activity -->
        <div class="bg-white rounded-3xl shadow-xl border border-gray-100 overflow-hidden">
            <div class="bg-gradient-to-r from-indigo-50 to-purple-100 px-6 py-4 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-900 flex items-center">
                    <i class="fas fa-clock text-indigo-500 mr-3"></i>
                    Recent Activity
                </h3>
            </div>
            <div class="p-6">
                <div class="space-y-4">
                    {% for activity in recent_activities[:5] %}
                    <div class="flex items-center space-x-4 p-4 bg-gray-50 rounded-xl border border-gray-100">
                        <div class="w-10 h-10 bg-gradient-to-br from-blue-400 to-purple-500 rounded-full flex items-center justify-center">
                            <i class="fas fa-{{ 'money-bill' if activity.type == 'contribution' else 'user' }} text-white text-sm"></i>
                        </div>
                        <div class="flex-1">
                            <p class="text-sm font-semibold text-gray-900">{{ activity.description }}</p>
                            <p class="text-xs text-gray-500">{{ activity.created_at.strftime('%b %d, %Y at %I:%M %p') }}</p>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            </div>
        </div>

        <!-- Payment Status -->
        <div class="bg-white rounded-3xl shadow-xl border border-gray-100 overflow-hidden">
            <div class="bg-gradient-to-r from-green-50 to-emerald-100 px-6 py-4 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-900 flex items-center">
                    <i class="fas fa-credit-card text-green-500 mr-3"></i>
                    Monthly Payment Status
                </h3>
            </div>
            <div class="p-6">
                <div class="grid grid-cols-2 gap-4 mb-6">
                    <div class="text-center p-4 bg-green-50 rounded-xl border border-green-200">
                        <div class="text-2xl font-bold text-green-600">{{ paid_members_count }}</div>
                        <div class="text-sm text-green-800 font-medium">Paid This Month</div>
                    </div>
                    <div class="text-center p-4 bg-red-50 rounded-xl border border-red-200">
                        <div class="text-2xl font-bold text-red-600">{{ unpaid_members_count }}</div>
                        <div class="text-sm text-red-800 font-medium">Payment Pending</div>
                    </div>
                </div>
                
                {% if unpaid_members %}
                <div class="space-y-2">
                    <h4 class="font-semibold text-gray-900 text-sm">Members with pending payments:</h4>
                    {% for member in unpaid_members[:3] %}
                    <div class="flex items-center justify-between p-3 bg-orange-50 rounded-lg border border-orange-200">
                        <div class="flex items-center space-x-3">
                            <div class="w-8 h-8 bg-orange-100 rounded-full flex items-center justify-center">
                                <span class="text-orange-600 font-bold text-xs">{{ member.custom_id }}</span>
                            </div>
                            <span class="text-sm font-medium text-gray-900">{{ member.full_name }}</span>
                        </div>
                        <span class="text-xs font-semibold text-orange-600">Overdue</span>
                    </div>
                    {% endfor %}
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}