<?php
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

// Check current values
$lang = $_SESSION['selected_language'] ?? 'eng';
$curr = $_SESSION['selected_currency'] ?? 'usd';

// Test changing if requested
if (isset($_GET['test_lang'])) {
    $_SESSION['selected_language'] = $_GET['test_lang'];
    $lang = $_GET['test_lang'];
}

if (isset($_GET['test_curr'])) {
    $_SESSION['selected_currency'] = $_GET['test_curr'];
    $curr = $_GET['test_curr'];
}

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

$lang_names = ['eng' => 'English', 'ita' => 'Italiano', 'esp' => 'Español', 'ger' => 'Deutsch'];
$curr_symbols = ['usd' => '$', 'eur' => '€', 'gbp' => '£', 'cad' => 'C$'];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>✅ FINAL FIX TEST</title>
    <style>
        body { font-family: Arial; padding: 40px; background: #f5f5f5; }
        .container { max-width: 600px; margin: 0 auto; background: white; padding: 40px; border-radius: 10px; box-shadow: 0 2px 20px rgba(0,0,0,0.1); }
        h1 { color: #4CAF50; text-align: center; margin-top: 0; }
        .status { background: #e8f5e9; padding: 20px; border-radius: 5px; border-left: 4px solid #4CAF50; margin: 20px 0; }
        .status-item { padding: 10px 0; font-size: 16px; }
        .status-item strong { color: #2e7d32; }
        .value { font-family: monospace; background: #f0f0f0; padding: 5px 10px; border-radius: 3px; }
        .test-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
        button { padding: 12px; background: #2196F3; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; }
        button:hover { background: #0b7dda; }
        .price-test { background: #fff9c4; padding: 20px; border-radius: 5px; text-align: center; margin: 20px 0; }
        .price-value { font-size: 36px; color: #F07E2D; font-weight: bold; }
    </style>
</head>
<body>

<div class="container">
    <h1>✅ FIX COMPLETE!</h1>

    <div class="status">
        <h2>Current Settings</h2>
        <div class="status-item">
            <strong>Language:</strong> <span class="value"><?php echo strtoupper($lang); ?> (<?php echo $lang_names[$lang] ?? 'Unknown'; ?>)</span>
        </div>
        <div class="status-item">
            <strong>Currency:</strong> <span class="value"><?php echo strtoupper($curr); ?> (<?php echo $curr_symbols[$curr]; ?>)</span>
        </div>
        <div class="status-item">
            <strong>Session Status:</strong> <span class="value" style="color: #4CAF50;">✓ ACTIVE</span>
        </div>
    </div>

    <div class="price-test">
        <p><strong>Price Conversion</strong></p>
        <p style="color: #666; font-size: 14px;">€100 in <?php echo strtoupper($curr); ?></p>
        <div class="price-value"><?php echo getPriceDisplay(100); ?></div>
    </div>

    <div class="test-buttons">
        <div>
            <h3 style="margin-top: 0;">Languages</h3>
            <button onclick="location.href='?test_lang=eng'">English</button>
            <button onclick="location.href='?test_lang=ita'">Italiano</button>
            <button onclick="location.href='?test_lang=esp'">Español</button>
            <button onclick="location.href='?test_lang=ger'">Deutsch</button>
        </div>
        <div>
            <h3 style="margin-top: 0;">Currencies</h3>
            <button onclick="location.href='?test_curr=usd'">USD ($)</button>
            <button onclick="location.href='?test_curr=eur'">EUR (€)</button>
            <button onclick="location.href='?test_curr=gbp'">GBP (£)</button>
            <button onclick="location.href='?test_curr=cad'">CAD (C$)</button>
        </div>
    </div>

    <div style="background: #e3f2fd; padding: 20px; border-radius: 5px; text-align: center;">
        <p><strong>✓ All issues fixed!</strong></p>
        <p>Language and currency system now works correctly.</p>
        <button onclick="location.href='index.php'" style="width: 100%; margin-top: 10px;">→ Go to Homepage</button>
    </div>
</div>

</body>
</html>
