<?php
// Test file to verify language and currency functionality

if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

require_once __DIR__ . '/config/currency_converter.php';

// Simulate language change
if (isset($_GET['setlang'])) {
    $_SESSION['selected_language'] = $_GET['setlang'];
}

// Simulate currency change
if (isset($_GET['setcurr'])) {
    $_SESSION['selected_currency'] = $_GET['setcurr'];
}

$language_map = ['ITA' => 'it', 'ENG' => 'en', 'ESP' => 'es', 'GER' => 'de'];
$current_lang = $_SESSION['selected_language'] ?? 'ITA';
$html_lang = $language_map[$current_lang] ?? 'it';
$current_currency = $_SESSION['selected_currency'] ?? 'EUR';

?>
<!DOCTYPE html>
<html lang="<?php echo $html_lang; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Language & Currency</title>
    <style>
        body { font-family: Arial; padding: 20px; }
        .info { background: #f0f0f0; padding: 15px; margin: 10px 0; border-radius: 5px; }
        .price { font-size: 24px; color: #F07E2D; font-weight: bold; }
        a { display: inline-block; margin: 5px; padding: 8px 15px; background: #007bff; color: white; text-decoration: none; border-radius: 3px; }
        a:hover { background: #0056b3; }
    </style>
</head>
<body>

<h1>Language & Currency Test</h1>

<div class="info">
    <h3>Current Status</h3>
    <p><strong>HTML Language Attribute:</strong> <code><?php echo $html_lang; ?></code></p>
    <p><strong>Session Language:</strong> <code><?php echo $_SESSION['selected_language'] ?? 'Not set'; ?></code></p>
    <p><strong>Session Currency:</strong> <code><?php echo $_SESSION['selected_currency'] ?? 'EUR'; ?></code></p>
</div>

<div class="info">
    <h3>Change Language (sets browser language)</h3>
    <a href="?setlang=ITA">Italiano (IT)</a>
    <a href="?setlang=ENG">English (EN)</a>
    <a href="?setlang=ESP">Español (ES)</a>
    <a href="?setlang=GER">Deutsch (DE)</a>
</div>

<div class="info">
    <h3>Change Currency</h3>
    <a href="?setcurr=EUR">Euro (€)</a>
    <a href="?setcurr=USD">Dollar ($)</a>
    <a href="?setcurr=GBP">Pound (£)</a>
    <a href="?setcurr=CAD">Canadian ($)</a>
</div>

<div class="info">
    <h3>Price Conversion Test</h3>
    <p>Test price: €100</p>
    <p>Converted price: <span class="price"><?php echo getPriceDisplay(100); ?></span></p>
    <p>Current currency from session: <code><?php echo $_SESSION['selected_currency'] ?? 'EUR'; ?></code></p>
</div>

<div class="info">
    <h3>Browser Translation</h3>
    <p>When you change the language, browsers like Chrome will offer to translate the page automatically!</p>
    <p>The HTML lang attribute is set to: <code>&lt;html lang="<?php echo $html_lang; ?>"&gt;</code></p>
    <p style="color: #666; font-size: 12px;">Look for the browser's "Translate" button (usually in the address bar).</p>
</div>

</body>
</html>
