<?php
// ajax_search_games.php
require 'config/db.php';

$q = $_GET['q'] ?? "";
$games = [];

if (!empty($q)) {
    // Consulta limpia: Solo busca por nombre y limita resultados
    $stmt = $pdo->prepare("SELECT name, slug FROM games WHERE name LIKE ? ORDER BY name ASC LIMIT 5");
    $stmt->execute(['%' . $q . '%']);
    $games = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

header('Content-Type: application/json');
echo json_encode($games);