<?php
$base = defined('APP_BASE') ? APP_BASE : '';
if ($base !== '') {
    ob_start(function (string $html) use ($base): string {
        // Skip URLs already prefixed with $base/ so a render-time APP_BASE
        // prefix in the HTML is not doubled.
        $skip = preg_quote(ltrim($base, '/'), '/');
        return preg_replace('/(href|action|src)="\/(?!\/|' . $skip . '\/)/', '$1="' . $base . '/', $html);
    });
}
$appName = function_exists('Helper::getSetting') || class_exists('Helper')
    ? Helper::getSetting('app_name', 'Plenvo')
    : 'Plenvo';
?>
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($appName) ?> – Externe Ansicht</title>
    <link rel="stylesheet" href="/assets/css/app.css">
    <link rel="icon" href="/assets/img/favicon.svg" type="image/svg+xml">
</head>
<body class="ext-body">
<header class="ext-header">
    <div class="ext-header-inner">
        <div class="ext-logo">
            <svg viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" width="28" height="28">
                <rect width="40" height="40" rx="10" fill="#4f46e5"/>
                <path d="M10 14h20M10 20h14M10 26h18" stroke="white" stroke-width="2.5" stroke-linecap="round"/>
            </svg>
            <span><?= htmlspecialchars($appName) ?></span>
        </div>
        <?php if (!empty($external)): ?>
        <div class="ext-header-meta">
            <span class="ext-project-dot" style="background:<?= htmlspecialchars($external['project_color'] ?? '#4f46e5') ?>"></span>
            <span class="ext-project-name"><?= htmlspecialchars($external['project_name'] ?? '') ?></span>
            <span class="ext-user-name"><?= htmlspecialchars($external['name'] ?? '') ?></span>
        </div>
        <?php endif; ?>
    </div>
</header>
<main class="ext-main">
    <?= $content ?>
</main>
<script nonce="<?= csp_nonce() ?>" src="/assets/js/app.js?v=<?= APP_VERSION ?>"></script>
</body>
</html>
