<?php
declare(strict_types=1);

function qrator_base_path(): string {
    $script = str_replace('\\', '/', $_SERVER['SCRIPT_NAME'] ?? '');
    $dir = rtrim(dirname($script), '/');
    return ($dir === '' || $dir === '.') ? '' : $dir;
}
function qrator_url(string $path = ''): string {
    return qrator_base_path() . '/' . ltrim($path, '/');
}
function qrator_admin_url(): string {
    return qrator_url('admin/login.php');
}
function qrator_e(string $value): string {
    return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
function qrator_front_header(string $title, string $description): void {
    $fullTitle = $title . ' | QRator';
    $canonical = qrator_url(basename($_SERVER['SCRIPT_NAME'] ?? 'index.php'));
?>
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= qrator_e($fullTitle) ?></title>
<meta name="description" content="<?= qrator_e($description) ?>">
<link rel="canonical" href="<?= qrator_e($canonical) ?>">
<link rel="stylesheet" href="<?= qrator_e(qrator_url('public/assets/frontend.css')) ?>">
</head>
<body class="front-body">
<header class="front-header">
  <a class="front-brand" href="<?= qrator_e(qrator_url('index.php')) ?>" aria-label="QRator Startseite">
    <img src="<?= qrator_e(qrator_url('public/assets/qrator-mark.png')) ?>" alt="QRator Logo">
    <span><strong>QRator</strong><small>QR-Code Manager</small></span>
  </a>
  <nav class="front-nav" aria-label="Hauptnavigation">
    <a href="<?= qrator_e(qrator_url('qr-codes.php')) ?>">QR-Codes</a>
    <a href="<?= qrator_e(qrator_url('dynamische-qr-codes.php')) ?>">Dynamische QR-Codes</a>
    <a href="<?= qrator_e(qrator_url('vorteile.php')) ?>">Vorteile</a>
    <a href="<?= qrator_e(qrator_url('qr-code-generator.php')) ?>">Generator</a>
    <a href="<?= qrator_e(qrator_url('faq.php')) ?>">FAQ</a>
  </nav>
  <a class="front-login" href="<?= qrator_e(qrator_admin_url()) ?>">Login</a>
</header>
<main>
<?php }
function qrator_front_footer(): void { ?>
</main>
<footer class="front-footer">
  <div>
    <strong>QRator</strong>
    <p>Dynamische QR-Codes auf dem eigenen Webserver verwalten.</p>
  </div>
  <div class="front-footer-links">
    <a href="<?= qrator_e(qrator_url('faq.php')) ?>">FAQ</a>
    <a href="<?= qrator_e(qrator_admin_url()) ?>">Login</a>
    <a href="<?= qrator_e(qrator_url('install.php')) ?>">Installation</a>
  </div>
</footer>
</body>
</html>
<?php }
