<?php
require 'db.php';

$page  = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 15;
$offset = $page * $limit;

$stmt = $pdo->prepare("
    SELECT 
        u.id,
        u.username,
        u.firstname,
        u.secondname,
        u.email,
        u.role,
        u.is_verified,
        CASE 
            WHEN u.is_verified = 1 
            THEN 1
            ELSE 0
        END AS is_approved
    FROM users u
    ORDER BY is_approved ASC
    LIMIT :limit OFFSET :offset
");

$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

    
    echo "<tr>";
   echo "<tr data-session-id='{$row['id']}'>";
   echo "<td>{$row['username']}</td>";
echo "<td>{$row['firstname']}</td>";
echo "<td>{$row['secondname']}</td>";
echo "<td>{$row['email']}</td>";


echo "<td class='text-end action-cell'>";
if (!$row['is_approved']) {
    echo "<button class='btn btn-sm btn-success'
            onclick='admin_approve_User({$row['id']})'>
            Approve
          </button>";
} else {
    echo "-";
}
echo "</td>";
echo "</tr>";
}
