<?php
header('Content-Type: application/json');
require_once '../api/tmdb.php';

$query = $_GET['q'] ?? '';

if (empty($query)) {
    echo json_encode(['success' => false, 'message' => 'Query is required']);
    exit;
}

$results = searchMedia($query);

if ($results) {
    echo json_encode([
        'success' => true,
        'results' => $results['results'] ?? [],
        'total_results' => $results['total_results'] ?? 0
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'No results found'
    ]);
}
