<?php
require_once '../../includes/config.php';
requireAdmin();
header('Content-Type: application/json');

$uid = intval($_GET['user_id'] ?? 0);
if (!$uid) { echo '[]'; exit; }

$db = getDB();
try {
    $s = $db->prepare("SELECT id, device_name, browser, os, ip_address, country, city, is_blocked, is_active, login_count, DATE_FORMAT(last_seen,'%d %b, %H:%i') as last_seen FROM user_devices WHERE user_id=? ORDER BY last_seen DESC");
    $s->execute([$uid]);
    echo json_encode($s->fetchAll());
} catch(Exception $e) {
    echo '[]';
}
