<?php
/**
 * Currency Conversion Helper
 */

$exchangeRates = [
    'eur' => 1.0,      // Base currency
    'usd' => 1.10,     // EUR to USD
    'gbp' => 0.87,     // EUR to GBP
    'cad' => 1.48      // EUR to CAD
];

$currencySymbols = [
    'eur' => '€',
    'usd' => '$',
    'gbp' => '£',
    'cad' => 'C$'
];

function convertPrice($priceInEuro, $currency = 'eur') {
    global $exchangeRates;
    $currency = strtolower($currency);
    
    if (!isset($exchangeRates[$currency])) {
        return $priceInEuro;
    }
    
    return round($priceInEuro * $exchangeRates[$currency], 2);
}

function formatPrice($price, $currency = 'eur') {
    global $currencySymbols;
    $currency = strtolower($currency);
    $symbol = $currencySymbols[$currency] ?? '€';
    
    return $symbol . number_format($price, 2, '.', ',');
}

function getPriceDisplay($euroPrice) {
    if (session_status() !== PHP_SESSION_ACTIVE) {
        session_start();
    }
    
    $currency = $_SESSION['selected_currency'] ?? 'eur';
    $convertedPrice = convertPrice($euroPrice, $currency);
    
    return formatPrice($convertedPrice, $currency);
}
?>
