<?php
require_once __DIR__ . '/../config/db.php';

$search_uid = trim($_GET['search_uid'] ?? '');

$sql = "SELECT * FROM uid_pool";
$cond = [];

if ($search_uid !== '') {
    $cond[] = "uid LIKE :q";
}

if ($cond) $sql .= " WHERE " . implode(" AND ", $cond);
$sql .= " ORDER BY first_seen DESC";

$stmt = $pdo->prepare($sql);

if ($search_uid !== '') {
    $stmt->bindValue(":q", "%$search_uid%");
}

$stmt->execute();

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
exit;
