<?php
function page_head(string $title, array $opt = []): void {
    $lang = lang();
    $other = $lang === 'pt' ? 'en' : 'pt';
    $qs = $_GET; $qs['lang'] = $other;
    $switch = strtok($_SERVER['REQUEST_URI'] ?? '/', '?') . '?' . http_build_query($qs);
    $desc = $opt['description'] ?? t('meta_desc');
    ?><!doctype html>
<html lang="<?= $lang === 'pt' ? 'pt-PT' : 'en' ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= e($title) ?> · SherlockHomes</title>
<meta name="description" content="<?= e($desc) ?>">
<?php if (!empty($opt['noindex'])): ?><meta name="robots" content="noindex"><?php endif; ?>
<link rel="icon" href="/assets/favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="/assets/style.css?v=2">
</head>
<body>
<a class="skip" href="#main"><?= e(t('skip')) ?></a>
<header class="site-head">
  <div class="wrap head-row">
    <a class="logo" href="/">
      <img src="/assets/sherlockLOGO.jpg" alt="SherlockHomes – <?= e(t('nav_home')) ?>" height="48">
    </a>
    <nav aria-label="<?= e(t('nav_main')) ?>">
      <ul>
        <li><a href="/how.php"><?= e(t('nav_how')) ?></a></li>
        <li><a href="/about.php"><?= e(t('nav_about')) ?></a></li>
        <li><a href="/donate.php"><?= e(t('nav_donate')) ?></a></li>
        <li><a href="<?= e($switch) ?>" lang="<?= $other === 'pt' ? 'pt-PT' : 'en' ?>" hreflang="<?= $other ?>"><?= $other === 'pt' ? 'Português' : 'English' ?></a></li>
      </ul>
    </nav>
  </div>
</header>
<main id="main" tabindex="-1">
<?php
}

function page_foot(array $opt = []): void {
    ?>
</main>
<footer class="site-foot">
  <div class="wrap foot-grid">
    <div>
      <p class="foot-mission"><?= e(t('tagline')) ?></p>
      <p class="small"><?= e(t('foot_independent')) ?></p>
    </div>
    <ul class="foot-links">
      <li><a href="/how.php"><?= e(t('nav_how')) ?></a></li>
      <li><a href="/about.php"><?= e(t('nav_about')) ?></a></li>
      <li><a href="/terms.php"><?= e(t('nav_terms')) ?></a></li>
      <li><a href="/privacy.php"><?= e(t('nav_privacy')) ?></a></li>
      <li><a href="/legal.php"><?= e(t('nav_legal')) ?></a></li>
      <li><a href="/report.php"><?= e(t('nav_report')) ?></a></li>
      <li><a href="/donate.php"><?= e(t('nav_donate')) ?></a></li>
    </ul>
  </div>
  <div class="wrap small foot-base">
    <?php if (!empty($opt['osm'])): ?><p><?= t('osm_attrib') ?></p><?php endif; ?>
    <p>© <?= date('Y') ?> SherlockHomes · <a href="mailto:<?= e(cfg('contact_email')) ?>"><?= e(cfg('contact_email')) ?></a></p>
  </div>
</footer>
<script src="/assets/app.js?v=1" defer></script>
</body>
</html>
<?php
}

function flash(string $msg, string $kind = 'info'): string {
    return '<div class="notice notice-' . e($kind) . '" role="' . ($kind === 'error' ? 'alert' : 'status') . '">' . $msg . '</div>';
}