<?php
// /esp32/dashboard/index.php
// Disclaimer: This example code is part of a research prototype.
// It is provided “as is”, without any warranty of any kind.
// Please review, adapt, and test carefully before using it in production.

require_once __DIR__ . '/auth.php';
require_login();

$page_title = 'Sites · ESP32 Dashboard';

// Fetch all configured sites.
$sites = pdo()
    ->query('SELECT id, name, slug, background_path FROM sites ORDER BY name')
    ->fetchAll();

$activeSite = null; // header.php uses this variable if present.

include __DIR__ . '/header.php';
?>
<section class="section">
  <h2 class="section-title">Sites</h2>
  <div class="site-grid">
    <?php foreach ($sites as $s): ?>
      <a class="site-card"
         href="<?= BASE_URL ?>/site.php?site=<?= urlencode($s['slug']) ?>"
         style="--bg:url('<?= htmlspecialchars($s['background_path'] ?? '', ENT_QUOTES) ?>')">
        <div class="site-card__overlay"></div>
        <div class="site-card__content">
          <h3><?= htmlspecialchars($s['name']) ?></h3>
          <p class="muted">Open dashboard</p>
        </div>
      </a>
    <?php endforeach; ?>
  </div>
</section>
<?php include __DIR__ . '/footer.php'; ?>
