<?php
/**
 * Templating Loader
 *
 * Beispiel:
 * tpl('header');                            // structure/header.php
 * tpl('hero', 'landing', 'main');           // landing/main/hero.php
 * tpl('faq', 'landing', 'fakecheck');       // landing/fakecheck/faq.php
 */

function tpl(string $file, string $type = 'structure', string $site = 'main'): void
{
    // Basisordner
    $base = __DIR__ . '/../partials/';

    // Erlaubte Typen & Sites
    $allowedTypes = ['structure', 'landing'];
    $allowedSites = ['main', 'fakecheck'];

    // Validierung
    if (!in_array($type, $allowedTypes)) {
        $type = 'structure';
    }

    if (!in_array($site, $allowedSites)) {
        $site = 'main';
    }

    // Zielpfad konstruieren
    if ($type === 'landing') {
        // landing -> landing/{site}/{file}.php
        $path = $base . "landing/$site/$file.php";
    } else {
        // structure -> structure/{file}.php
        $path = $base . "structure/$file.php";
    }

    // Datei laden
    if (file_exists($path)) {
        include $path;
    } else {
        echo "<!-- tpl(): Datei nicht gefunden: $path -->";
    }
}
