<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Dashboard | Pro Buy-Sell</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans antialiased">
    <div class="flex h-screen overflow-hidden">
        <!-- Sidebar -->
        <div class="w-64 bg-gray-900 text-white flex flex-col">
            <div class="p-5 text-2xl font-bold tracking-wider text-indigo-400">MarketPro</div>
            <nav class="flex-1 px-4 space-y-2">
                <a href="/admin" class="block px-4 py-2 rounded bg-gray-800 text-white font-medium">Dashboard</a>
                <a href="/admin/users" class="block px-4 py-2 rounded hover:bg-gray-800 text-gray-300">Users</a>
                <a href="/admin/listings" class="block px-4 py-2 rounded hover:bg-gray-800 text-gray-300">Listings</a>
                <a href="/logout" class="block px-4 py-2 rounded hover:bg-red-600 text-red-400 hover:text-white mt-10">Logout</a>
            </nav>
        </div>

        <!-- Main Content Area -->
        <div class="flex-1 flex flex-col overflow-y-auto">
            <header class="bg-white shadow-sm h-16 flex items-center justify-between px-8">
                <h1 class="text-xl font-semibold text-gray-800">Platform Overview</h1>
                <span class="text-sm font-medium text-gray-600">Logged in as Admin</span>
            </header>

            <main class="p-8">
                <!-- KPI Metrics Cards -->
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
                    <div class="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
                        <p class="text-sm text-gray-500 font-medium">Total Users</p>
                        <p class="text-3xl font-bold text-gray-800 mt-2"><%= stats.totalUsers %></p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
                        <p class="text-sm text-gray-500 font-medium">Total Listings</p>
                        <p class="text-3xl font-bold text-gray-800 mt-2"><%= stats.totalListings %></p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
                        <p class="text-sm text-gray-500 font-medium">Total Revenue ($)</p>
                        <p class="text-3xl font-bold text-emerald-600 mt-2">$<%= stats.totalRevenue || '0.00' %></p>
                    </div>
                </div>

                <!-- Recent Listings Table -->
                <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
                    <div class="px-6 py-4 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">Recent Marketplace Listings</h3>
                    </div>
                    <table class="w-full text-left border-collapse">
                        <thead>
                            <tr class="bg-gray-50 text-gray-600 text-xs uppercase tracking-wider">
                                <th class="px-6 py-3">ID</th>
                                <th class="px-6 py-3">Title</th>
                                <th class="px-6 py-3">Price</th>
                                <th class="px-6 py-3">Status</th>
                                <th class="px-6 py-3 text-right">Actions</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-200 text-sm">
                            <% listings.forEach(item => { %>
                                <tr>
                                    <td class="px-6 py-4 font-medium text-gray-900">#<%= item.id %></td>
                                    <td class="px-6 py-4 text-gray-700"><%= item.title %></td>
                                    <td class="px-6 py-4 text-gray-700">$<%= item.price %></td>
                                    <td class="px-6 py-4">
                                        <span class="px-2 py-1 text-xs rounded-full <%= item.status === 'active' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' %>">
                                            <%= item.status %>
                                        </span>
                                    </td>
                                    <td class="px-6 py-4 text-right">
                                        <form action="/admin/listing/delete/<%= item.id %>" method="POST" onsubmit="return confirm('Are you sure?');">
                                            <button type="submit" class="text-red-600 hover:text-red-900 font-medium">Remove</button>
                                        </form>
                                    </td>
                                </tr>
                            <% }) %>
                        </tbody>
                    </table>
                </div>
            </main>
        </div>
    </div>
</body>
</html>