<!DOCTYPE html>
\n<html lang="en">
\n<head>
\n    <meta charset="UTF-8">
\n    <meta name="viewport" content="width=device-width, initial-scale=1.0">
\n    <title>Web3 Analytics Dashboard</title>
\n    <script src="https://cdn.tailwindcss.com"></script>
\n</head>
\n<body class="bg-gray-50">
\n    <div class="min-h-screen py-8">
\n        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
\n            <!-- Header -->
\n            <div class="flex justify-between items-center mb-8">
\n                <h1 class="text-2xl font-semibold text-gray-900">Web3 Analytics</h1>
\n                <div class="text-sm text-gray-500">Last updated: <span class="font-medium"><?php echo date('Y-m-d H:i'); ?></span></div>
\n            </div>
\n
\n            <!-- Stats Grid -->
\n            <div class="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4 mb-8">
\n                <!-- Total Wallets -->
\n                <div class="bg-white overflow-hidden shadow rounded-lg">
\n                    <div class="p-5">
\n                        <div class="flex items-center">
\n                            <div class="flex-shrink-0">
\n                                <svg class="h-6 w-6 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
\n                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
\n                                </svg>
\n                            </div>
\n                            <div class="ml-5 w-0 flex-1">
\n                                <dl>
\n                                    <dt class="text-sm font-medium text-gray-500 truncate">Total Wallets</dt>
\n                                    <dd class="text-2xl font-semibold text-gray-900"><?php echo number_format($total_wallets); ?></dd>
\n                                </dl>
\n                            </div>
\n                        </div>
\n                    </div>
\n                </div>
\n
\n                <!-- Today's Detections -->
\n                <div class="bg-white overflow-hidden shadow rounded-lg">
\n                    <div class="p-5">
\n                        <div class="flex items-center">
\n                            <div class="flex-shrink-0">
\n                                <svg class="h-6 w-6 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
\n                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
\n                                </svg>
\n                            </div>
\n                            <div class="ml-5 w-0 flex-1">
\n                                <dl>
\n                                    <dt class="text-sm font-medium text-gray-500 truncate">Today</dt>
\n                                    <dd class="text-2xl font-semibold text-gray-900"><?php echo number_format($today_count); ?></dd>
\n                                </dl>
\n                            </div>
\n                        </div>
\n                    </div>
\n                </div>
\n
\n                <!-- Yesterday's Detections -->
\n                <div class="bg-white overflow-hidden shadow rounded-lg">
\n                    <div class="p-5">
\n                        <div class="flex items-center">
\n                            <div class="flex-shrink-0">
\n                                <svg class="h-6 w-6 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
\n                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
\n                                </svg>
\n                            </div>
\n                            <div class="ml-5 w-0 flex-1">
\n                                <dl>
\n                                    <dt class="text-sm font-medium text-gray-500 truncate">Yesterday</dt>
\n                                    <dd class="text-2xl font-semibold text-gray-900"><?php echo number_format($yesterday_count); ?></dd>
\n                                </dl>
\n                            </div>
\n                        </div>
\n                    </div>
\n                </div>
\n
\n                <!-- Unique Users -->
\n                <div class="bg-white overflow-hidden shadow rounded-lg">
\n                    <div class="p-5">
\n                        <div class="flex items-center">
\n                            <div class="flex-shrink-0">
\n                                <svg class="h-6 w-6 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
\n                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
\n                                </svg>
\n                            </div>
\n                            <div class="ml-5 w-0 flex-1">
\n                                <dl>
\n                                    <dt class="text-sm font-medium text-gray-500 truncate">Unique Users</dt>
\n                                    <dd class="text-2xl font-semibold text-gray-900"><?php echo number_format($unique_users); ?></dd>
\n                                </dl>
\n                            </div>
\n                        </div>
\n                    </div>
\n                </div>
\n            </div>
\n
\n            <!-- <b>Wallet</b> Distribution -->
\n            <div class="bg-white shadow rounded-lg mb-8">
\n                <div class="px-4 py-5 sm:px-6 border-b border-gray-200">
\n                    <h3 class="text-lg leading-6 font-medium text-gray-900"><b>Wallet</b> Distribution</h3>
\n                </div>
\n                <div class="p-6 grid grid-cols-1 gap-4 sm:grid-cols-2">
\n                    <?php foreach($wallet_distribution as $type => $data): ?>
\n                    <div class="bg-gray-50 rounded-lg p-4">
\n                        <div class="flex items-center justify-between">
\n                            <span class="text-sm font-medium text-gray-500"><?php echo htmlspecialchars($type); ?></span>
\n                            <span class="text-lg font-semibold text-gray-900"><?php echo $data['percentage']; ?>%</span>
\n                        </div>
\n                        <div class="mt-2 w-full bg-gray-200 rounded-full h-2.5">
\n                            <div class="bg-blue-600 h-2.5 rounded-full" style="width: <?php echo $data['percentage']; ?>%"></div>
\n                        </div>
\n                        <div class="mt-1 text-xs text-gray-500 text-right"><?php echo number_format($data['count']); ?> users</div>
\n                    </div>
\n                    <?php endforeach; ?>
\n                </div>
\n            </div>
\n
\n            <!-- Recent Activity Table -->
\n            <div class="bg-white shadow rounded-lg">
\n                <div class="px-4 py-5 sm:px-6 border-b border-gray-200">
\n                    <h3 class="text-lg leading-6 font-medium text-gray-900">Recent Activity</h3>
\n                </div>
\n                <div class="overflow-x-auto">
\n                    <table class="min-w-full divide-y divide-gray-200">
\n                        <thead class="bg-gray-50">
\n                            <tr>
\n                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
\n                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Timestamp</th>
\n                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"><b>Wallet</b> Type</th>
\n                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">IP Address</th>
\n                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Session ID</th>
\n                            </tr>
\n                        </thead>
\n                        <tbody class="bg-white divide-y divide-gray-200">
\n                            <?php foreach($recent_logs as $log): ?>
\n                            <tr>
\n                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
\n                                    <?php echo $log->id; ?>
\n                                </td>
\n                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
\n                                    <span title="<?php echo date('d/m/Y H:i:s', $log->timestamp); ?>">
\n                                        <?php echo $log->time_ago; ?>
\n                                    </span>
\n                                </td>
\n                                <td class="px-6 py-4 whitespace-nowrap">
\n                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
\n                                        <?php echo htmlspecialchars($log->wallet_type); ?>
\n                                    </span>
\n                                </td>
\n                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
\n                                    <?php echo htmlspecialchars($log->ip_address); ?>
\n                                </td>
\n                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
\n                                    <?php echo htmlspecialchars($log->session_id); ?>
\n                                </td>
\n                            </tr>
\n                            <?php endforeach; ?>
\n                        </tbody>
\n                    </table>
\n                </div>
\n
\n                <!-- Pagination -->
\n                <div class="bg-white px-4 py-3 border-t border-gray-200 sm:px-6">
\n                    <div class="flex items-center justify-between">
\n                        <div>
\n                            <p class="text-sm text-gray-700">
\n                                Showing 
\n                                <span class="font-medium"><?php echo ($pagination['current_page'] - 1) * $pagination['per_page'] + 1; ?></span> 
\n                                to 
\n                                <span class="font-medium">
\n                                    <?php echo min($pagination['current_page'] * $pagination['per_page'], $pagination['total']); ?>
\n                                </span> 
\n                                of 
\n                                <span class="font-medium"><?php echo $pagination['total']; ?></span> 
\n                                results
\n                            </p>
\n                        </div>
\n                        <div>
\n                            <nav class="relative z-0 inline-flex rounded-md shadow-sm -space-x-px" aria-label="Pagination">
\n                                <!-- First Page -->
\n                                <?php if($pagination['current_page'] > 1): ?>
\n                                    <a href="?page=1&key=<?php echo $key; ?>" 
\n                                       class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
\n                                        <span class="sr-only">First</span>
\n                                        <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
\n                                            <path fill-rule="evenodd" d="M15.707 15.707a1 1 0 01-1.414 0L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0l5 5a1 1 0 010 1.414z" clip-rule="evenodd" />
\n                                        </svg>
\n                                    </a>
\n                                <?php endif; ?>
\n
\n                                <!-- Previous Page -->
\n                                <?php if($pagination['current_page'] > 1): ?>
\n                                    <a href="?page=<?php echo $pagination['current_page']-1; ?>&key=<?php echo $key; ?>" 
\n                                       class="relative inline-flex items-center px-2 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
\n                                        <span class="sr-only">Previous</span>
\n                                        <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
\n                                            <path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
\n                                        </svg>
\n                                    </a>
\n                                <?php endif; ?>
\n
\n                                <!-- Page Numbers -->
\n                                <?php if($pagination['start'] > 1): ?>
\n                                    <span class="relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700">...</span>
\n                                <?php endif; ?>
\n
\n                                <?php for($i = $pagination['start']; $i <= $pagination['end']; $i++): ?>
\n                                    <a href="?page=<?php echo $i; ?>&key=<?php echo $key; ?>" 
\n                                       class="relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium <?php echo $i === $pagination['current_page'] ? 'z-10 bg-indigo-50 border-indigo-500 text-indigo-600' : 'text-gray-700 hover:bg-gray-50'; ?>">
\n                                        <?php echo $i; ?>
\n                                    </a>
\n                                <?php endfor; ?>
\n
\n                                <?php if($pagination['end'] < $pagination['total_pages']): ?>
\n                                    <span class="relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700">...</span>
\n                                <?php endif; ?>
\n
\n                                <!-- Next Page -->
\n                                <?php if($pagination['current_page'] < $pagination['total_pages']): ?>
\n                                    <a href="?page=<?php echo $pagination['current_page']+1; ?>&key=<?php echo $key; ?>" 
\n                                       class="relative inline-flex items-center px-2 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
\n                                        <span class="sr-only">Next</span>
\n                                        <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
\n                                            <path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
\n                                        </svg>
\n                                    </a>
\n                                <?php endif; ?>
\n
\n                                <!-- Last Page -->
\n                                <?php if($pagination['current_page'] < $pagination['total_pages']): ?>
\n                                    <a href="?page=<?php echo $pagination['total_pages']; ?>&key=<?php echo $key; ?>" 
\n                                       class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
\n                                        <span class="sr-only">Last</span>
\n                                        <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
\n                                            <path fill-rule="evenodd" d="M4.293 15.707a1 1 0 001.414 0L10 11.414l4.293 4.293a1 1 0 001.414-1.414l-5-5a1 1 0 00-1.414 0l-5 5a1 1 0 000 1.414z" clip-rule="evenodd" />
\n                                        </svg>
\n                                    </a>
\n                                <?php endif; ?>
\n                            </nav>
\n                        </div>
\n                    </div>
\n                </div>
\n            </div>
\n        </div>
\n    </div>
\n</body>
\n</html>