<?php
require_once __DIR__.'/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';
require_once __DIR__.'/../../engine/Logger.php';
$ctx = Kernel::handle(['auth' => 'admin']);
$admin = $ctx['user']; // admin session array
$u     = $admin;          // alias for backward compat
try {
    $pending = db()->prepare("SELECT k.*, u.name, u.phone FROM kyc_verifications k JOIN users u ON u.id=k.user_id WHERE k.status='pending' ORDER BY k.created_at ASC LIMIT 50");
    $pending->execute();
    echo json_encode(['ok'=>true,'data'=>$pending->fetchAll()], JSON_UNESCAPED_UNICODE);
} catch(Throwable $e){http_response_code(500);echo json_encode(['error' => 'server_error', 'message' => 'خطأ مؤقت — حاول مرة أخرى'], JSON_UNESCAPED_UNICODE);}
