<?php
declare(strict_types=1);
@ini_set('display_errors', '0');
@error_reporting(E_ALL);
@date_default_timezone_set('Europe/Rome');

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

$projectName = 'EXTREMELOT';
$view = $_GET['view'] ?? 'mappa';

// Simple healthz check
if (isset($_GET['healthz'])) {
    header('Content-Type: text/plain');
    echo "OK\nPHP: " . PHP_VERSION . "\nTime: " . date('Y-m-d H:i:s');
    exit;
}

// Presenti mock data based on screenshot
$presenti = [
    ['color' => 'blue', 'name' => 'Caudex', 'action' => 'lascia Lot'],
    ['color' => 'red', 'name' => 'Rebo', 'action' => 'giunge a Lot'],
    ['color' => 'dark', 'name' => 'Xoriane', 'action' => 'giunge a Lot'],
    ['color' => 'steel', 'name' => 'Helle', 'action' => 'giunge a Lot'],
    ['color' => 'gold', 'name' => 'Samara', 'action' => 'lascia Lot'],
    ['color' => 'gold', 'name' => 'Eaoden', 'action' => 'lascia Lot'],
    ['color' => 'violet', 'name' => 'Zizka', 'action' => 'giunge a Lot'],
    ['color' => 'green', 'name' => 'Esma', 'action' => 'giunge a Lot'],
    ['color' => 'blue', 'name' => 'Caudex', 'action' => 'giunge a Lot'],
];

?>
<!doctype html>
<html lang="it">
<head>
  <meta charset="utf-8" />
  <title><?= $projectName ?></title>
  <link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
</head>
<body>
  <div class="elot-wrapper">
    <!-- SIDEBAR -->
    <aside class="elot-sidebar">
      <div class="sidebar-top-black"></div>
      <div class="sidebar-date">
        Anno XXVIII, Mese 11°, Giorno 9°<br>
        <span style="font-size: 13px;">GRAN DUCATO DI PETRUS</span>
      </div>
      
      <div class="location-frame">
          <div class="location-img" role="img" aria-label="Gran Ducato di Petrus"></div>
          <div class="location-title">Via dei Mulini</div>
      </div>

      <div class="nav-grid">
          <div class="nav-btn">Ovest</div>
          <div class="nav-btn">Sud</div>
          <div class="nav-btn">Est</div>
          <div class="nav-btn" style="background: #f0e2b6; color: #000;">ENTRA</div>
      </div>

      <div class="sidebar-desc">
          A OVEST la strada continua, ad EST c'e' il Pozzo del disonore. A SUD il Piazzale di LOT, entrando si accede alla Bacheca.
      </div>

      <div class="guardia-header">Dal Corpo di Guardia</div>

      <div class="guardia-date">Anno XXVIII, Mese 11°, Giorno 9°</div>
      
      <div class="adventure-frame">
        <div class="adventure-img" role="img" aria-label="Adventurelot"></div>
        <div class="adventure-caption">Il Dungeon di Vetrovania</div>
      </div>
      
      <div class="clock-area">
          <div class="clock-text"><?= date('H:i') ?></div>
          <div style="font-size: 20px;">🌘</div>
      </div>

      <div class="presenti-box">
          <div class="presenti-count">
              Dal Corpo di Guardia:<br>
              390 persone in ExtremeLands
          </div>
          <?php foreach ($presenti as $p): ?>
          <div class="presenti-entry">
              <span class="presenti-icon is-<?= $p['color'] ?>"></span>
              <a href="#" class="presenti-name"><?= $p['name'] ?></a>
              <span style="color: #444; font-size: 10px;"><?= $p['action'] ?></span>
          </div>
          <?php endforeach; ?>
      </div>

      <div class="sidebar-actions">
          <button class="action-btn-green">Dove vuoi andare a giocare OGGI?</button>
          <button class="action-btn-green">Con chi vuoi giocare OGGI?</button>
          <button class="bazar-btn">BAZAR</button>
      </div>

      <div class="sidebar-banner">CARNEVALOT!</div>
    </aside>

    <!-- TOP TABS -->
    <header class="elot-header">
      <a href="?view=posta" class="elot-tab <?= $view === 'posta' ? 'active' : '' ?>">Posta</a>
      <a href="?view=mappa" class="elot-tab <?= $view === 'mappa' ? 'active' : '' ?>">LOT</a>
      <a href="?view=scheda" class="elot-tab <?= $view === 'scheda' ? 'active' : '' ?>">Scheda</a>
      <a href="?view=presenti" class="elot-tab">Presenti</a>
      <a href="?view=simboli" class="elot-tab">Simboli</a>
      <a href="?view=regole" class="elot-tab">Regole</a>
      <a href="?view=azioni" class="elot-tab">Azioni</a>
    </header>

    <!-- MAIN CONTENT -->
    <main class="elot-main">
        <?php if ($view === 'mappa'): ?>
            <div class="map-wrapper">
                <div class="map-frame">
                    <div class="map-canvas" role="img" aria-label="Mappa del Regno"></div>
                </div>
            </div>
            
            <div class="map-footer">
                <a href="#" class="map-link-btn">Mappa del Regno</a>
                <a href="#" class="map-link-btn">Mappa delle Isole</a>
                <a href="#" class="map-link-btn">Mappa Testuale</a>
                <a href="#" class="map-link-btn" style="background: #5d4037;">Esci da Lot</a>
            </div>
        <?php elseif ($view === 'scheda'): ?>
            <div style="background: var(--parchment); border: 2px solid #5d4037; padding: 40px; max-width: 600px; width: 90%; margin-top: 20px; box-shadow: 0 0 10px rgba(0,0,0,0.3);">
                <h1 style="color: var(--dark-red); text-align: center; font-variant: small-caps;">Scheda del Personaggio</h1>
                <p style="text-align: center; font-style: italic;">Sotto sviluppo...</p>
            </div>
        <?php else: ?>
            <div style="background: var(--parchment); border: 2px solid #5d4037; padding: 40px; margin-top: 20px;">
                <h1 style="color: var(--dark-red);"><?= strtoupper($view) ?></h1>
                <p>Area in fase di allestimento.</p>
            </div>
        <?php endif; ?>
    </main>
  </div>
</body>
</html>
