<?php
// factors/evacuation.php — Эвакуация дипломатов
$api_url = 'https://' . $_SERVER['HTTP_HOST'] . '/api/latest.php';
$cache_file = __DIR__ . '/cache/evacuation.json';
$cache_ttl = 300;

if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $cache_ttl) {
    $data = json_decode(file_get_contents($cache_file), true);
} else {
    $raw = @file_get_contents($api_url);
    $data = $raw ? json_decode($raw, true) : ['components' => ['evacuation' => ['raw' => 1, 'score' => 2.0]]];
    if (!is_dir(dirname($cache_file))) mkdir(dirname($cache_file), 0755, true);
    file_put_contents($cache_file, json_encode($data));
}

$factor = $data['components']['evacuation'] ?? ['raw' => 1, 'score' => 2.0];
$current_level = $factor['raw'];
$current_score = $factor['score'];
?>
<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Эвакуация дипломатов</title>
    <style>
        body { font-family: Arial; background: #0f172a; color: #e2e8f0; padding: 2rem; }
        .card { background: #1e293b; padding: 1.5rem; border-radius: 12px; max-width: 600px; margin: auto; }
        .value { font-size: 2.5rem; font-weight: 700; color: #f59e0b; }
    </style>
</head>
<body>
    <div class="card">
        <h2>Эвакуация дипломатов</h2>
        <p>Текущее значение:</p>
        <div class="value"><?= $current_level ?>/5</div>
        <p>Вклад в индекс: <strong><?= $current_score ?></strong> из 10</p>
    </div>
</body>
</html>