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

{% block title %}{{ group.name }} - Group Dashboard{% endblock %}

{% block content %}
<div class="px-4 py-6 mx-auto max-w-screen-xl">
    <!-- Group Header -->
    <div class="mb-8 bg-gradient-to-r from-blue-600 to-blue-800 rounded-lg p-6 text-white">
        <div class="flex items-center justify-between">
            <div>
                <h1 class="text-3xl font-bold">{{ group.name }}</h1>
                <p class="text-blue-100 mt-2">{{ group.description or 'Group savings management' }}</p>
                <div class="flex items-center space-x-4 mt-3">
                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-500 bg-opacity-50">
                        <i class="fas fa-tag mr-2"></i>
                        {{ group.group_code }}
                    </span>
                    <span class="text-blue-100">
                        <i class="fas fa-coins mr-2"></i>
                        {{ group.currency_ref.symbol if group.currency_ref else '৳' }} {{ group.currency_ref.code if group.currency_ref else 'BDT' }}
                    </span>
                </div>
            </div>
            <div class="text-right">
                <div class="text-3xl font-bold">{{ total_members }}</div>
                <div class="text-blue-100">Total Members</div>
            </div>
        </div>
    </div>

    <!-- Quick Stats -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
        <div class="bg-white rounded-lg shadow p-6">
            <div class="flex items-center">
                <div class="flex-shrink-0">
                    <div class="w-8 h-8 bg-green-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-money-bill-wave text-green-600"></i>
                    </div>
                </div>
                <div class="ml-4">
                    <p class="text-sm font-medium text-gray-500">Total Contributions</p>
                    <p class="text-2xl font-semibold text-gray-900">{{ group.currency_ref.symbol if group.currency_ref else '৳' }}{{ "{:,.2f}".format(total_contributions) }}</p>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-lg shadow p-6">
            <div class="flex items-center">
                <div class="flex-shrink-0">
                    <div class="w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-calendar-alt text-blue-600"></i>
                    </div>
                </div>
                <div class="ml-4">
                    <p class="text-sm font-medium text-gray-500">This Month</p>
                    <p class="text-2xl font-semibold text-gray-900">{{ group.currency_ref.symbol if group.currency_ref else '৳' }}{{ "{:,.2f}".format(monthly_contributions) }}</p>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-lg shadow p-6">
            <div class="flex items-center">
                <div class="flex-shrink-0">
                    <div class="w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-target text-purple-600"></i>
                    </div>
                </div>
                <div class="ml-4">
                    <p class="text-sm font-medium text-gray-500">Monthly Target</p>
                    <p class="text-2xl font-semibold text-gray-900">{{ group.currency_ref.symbol if group.currency_ref else '৳' }}{{ "{:,.2f}".format(monthly_target) }}</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Group Management Actions -->
    <div class="bg-white rounded-lg shadow mb-8">
        <div class="px-6 py-4 border-b border-gray-200">
            <h2 class="text-lg font-semibold text-gray-900">Group Management</h2>
        </div>
        <div class="p-6">
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                <a href="{{ url_for('admin_members') }}" class="flex items-center p-4 bg-blue-50 rounded-lg hover:bg-blue-100 transition-colors">
                    <div class="flex-shrink-0">
                        <i class="fas fa-users text-blue-600 text-xl"></i>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-900">Manage Members</p>
                        <p class="text-xs text-gray-500">Add, edit, remove members</p>
                    </div>
                </a>

                <a href="{{ url_for('admin_contributions') }}" class="flex items-center p-4 bg-green-50 rounded-lg hover:bg-green-100 transition-colors">
                    <div class="flex-shrink-0">
                        <i class="fas fa-money-bill-wave text-green-600 text-xl"></i>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-900">Contributions</p>
                        <p class="text-xs text-gray-500">Track and manage payments</p>
                    </div>
                </a>

                <a href="{{ url_for('admin_events') }}" class="flex items-center p-4 bg-purple-50 rounded-lg hover:bg-purple-100 transition-colors">
                    <div class="flex-shrink-0">
                        <i class="fas fa-calendar-alt text-purple-600 text-xl"></i>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-900">Events</p>
                        <p class="text-xs text-gray-500">Big collection events</p>
                    </div>
                </a>

                <a href="{{ url_for('admin_reports') }}" class="flex items-center p-4 bg-orange-50 rounded-lg hover:bg-orange-100 transition-colors">
                    <div class="flex-shrink-0">
                        <i class="fas fa-chart-bar text-orange-600 text-xl"></i>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-900">Reports</p>
                        <p class="text-xs text-gray-500">Analytics and insights</p>
                    </div>
                </a>
            </div>
        </div>
    </div>

    <!-- Recent Group Activity -->
    <div class="bg-white rounded-lg shadow">
        <div class="px-6 py-4 border-b border-gray-200">
            <h2 class="text-lg font-semibold text-gray-900">Recent Activity</h2>
        </div>
        <div class="p-6">
            {% if recent_contributions %}
            <div class="space-y-4">
                {% for contribution in recent_contributions %}
                <div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
                    <div class="flex items-center">
                        <div class="flex-shrink-0">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center">
                                <span class="text-blue-600 font-semibold text-sm">{{ contribution.member.custom_id or 'M' }}</span>
                            </div>
                        </div>
                        <div class="ml-4">
                            <p class="text-sm font-medium text-gray-900">{{ contribution.member.full_name }}</p>
                            <p class="text-xs text-gray-500">{{ contribution.contribution_type.title() }} contribution</p>
                        </div>
                    </div>
                    <div class="text-right">
                        <p class="text-sm font-semibold text-gray-900">{{ group.currency_ref.symbol if group.currency_ref else '৳' }}{{ "{:,.2f}".format(contribution.amount) }}</p>
                        <p class="text-xs text-gray-500">{{ contribution.created_at.strftime('%b %d, %Y') }}</p>
                    </div>
                </div>
                {% endfor %}
            </div>
            {% else %}
            <div class="text-center py-8">
                <div class="text-gray-400 mb-4">
                    <i class="fas fa-inbox text-4xl"></i>
                </div>
                <p class="text-gray-500">No recent activity in this group</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}