<?php
/**
 * Translation Service API
 * Uses a mapping or simple logic to translate strings dynamicallly.
 * Can be expanded to use Gemini API.
 */
header('Content-Type: application/json');
session_start();

if (!isset($_SESSION['userid'])) {
    http_response_code(403);
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}

$input = json_decode(file_get_contents('php://input'), true);
$text = $input['text'] ?? '';
$targetLang = $input['targetLang'] ?? 'en';

if (empty($text)) {
    echo json_encode(['translatedText' => '']);
    exit;
}

// In a real scenario, we could call Gemini here.
// For now, if it's not in the JS map, we'll just return it or use a small PHP side map.
$phpMap = [
    "مدرسہ منیجیمنٹ سسٹم" => "Madrasa Management System",
    // ... add more if needed
];

$translated = $phpMap[$text] ?? $text; // Fallback to original

echo json_encode(['translatedText' => $translated]);
