<?php

declare(strict_types=1);

/**
 * <head>-Inhalt. Props: $meta (array aus der Page), $current (Slug).
 * $meta: title, description, og_image (optional, Pfad relativ zu assets/),
 *        title_absolute (bool — Title ohne Suffix), scripts (array zusätzlicher JS-Dateien).
 */
$club = json_load('club');

$title = $meta['title'] ?? $club['name'];
if (empty($meta['title_absolute'])) {
    $title .= ' | ' . $club['name'];
}
$description = $meta['description'] ?? $club['description'];
$canonical = abs_url($current === '404' ? '' : $current);
$ogImage = rtrim((string) config('base_url'), '/') . '/assets/' . ltrim($meta['og_image'] ?? 'img/og-default.jpg', '/');
$scripts = array_merge(['nav.js', 'back-to-top.js'], $meta['scripts'] ?? []);
?>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= e($title) ?></title>
    <meta name="description" content="<?= e($description) ?>">
<?php /* noindex: 404-Seiten und alles, was eine Page ausdrücklich anfordert
         ($meta['noindex'], z. B. Stadionzeitungs-Entwürfe) — dann auch kein
         Self-Canonical, das wäre ein Widerspruch zur Nicht-Indexierung. */ ?>
<?php if ($current !== '404' && empty($meta['noindex'])): ?>
    <link rel="canonical" href="<?= e($canonical) ?>">
<?php else: ?>
    <meta name="robots" content="noindex">
<?php endif; ?>
    <meta name="theme-color" content="#222222">
    <meta property="og:type" content="website">
    <meta property="og:site_name" content="<?= e($club['name']) ?>">
    <meta property="og:title" content="<?= e($title) ?>">
    <meta property="og:description" content="<?= e($description) ?>">
    <meta property="og:url" content="<?= e($canonical) ?>">
    <meta property="og:image" content="<?= e($ogImage) ?>">
    <meta property="og:image:alt" content="<?= e($title) ?>">
    <meta property="og:locale" content="de_DE">
    <meta name="twitter:card" content="summary_large_image">
    <link rel="icon" href="/favicon.ico" sizes="32x32">
    <link rel="icon" href="<?= e(asset('img/logo.svg')) ?>" type="image/svg+xml">
<?php /* Preload ohne ?v= (asset(..., false)): base.css fordert dieselbe Datei per
         @font-face ohne Query an, mit Version wären es für den Browser zwei URLs
         und der Preload bliebe ungenutzt. */ ?>
<?php foreach (['fonts/coolvetica.woff2', 'fonts/abel.woff2'] as $font): ?>
<?php if (is_file(PUBLIC_PATH . '/assets/' . $font)): ?>
    <link rel="preload" href="<?= e(asset($font, false)) ?>" as="font" type="font/woff2" crossorigin>
<?php endif; ?>
<?php endforeach; ?>
<?php foreach (['tokens', 'reset', 'base', 'layout', 'components', 'utilities'] as $css): ?>
    <link rel="stylesheet" href="<?= e(asset("css/{$css}.css")) ?>">
<?php endforeach; ?>
<?php foreach ($scripts as $js): ?>
    <script defer src="<?= e(asset("js/{$js}")) ?>"></script>
<?php endforeach; ?>
<?php component('jsonld', ['extra' => $meta['schema'] ?? []]); ?>
