<?php
$base = defined('APP_BASE') ? APP_BASE : '';
if ($base !== '') {
    ob_start(function (string $html) use ($base): string {
        $html = preg_replace('/(href|action|src)="\/(?!\/)/', '$1="' . $base . '/', $html);
        return $html;
    });
}
?>
<!DOCTYPE html>
<html lang="<?= Lang::current() ?>" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= Helper::e($_appName) ?> – <?= isset($pageTitle) ? t($pageTitle) : t('login') ?></title>
    <link rel="stylesheet" href="/assets/css/app.css?v=<?= APP_VERSION ?>">
    <link rel="icon" href="/assets/img/favicon.svg" type="image/svg+xml">
</head>
<?php
$_dbReady    = file_exists(DB_PATH);
$_appName    = $_dbReady ? Helper::getSetting('app_name', 'Plenvo') : 'Plenvo';
$_privacyUrl = $_dbReady ? Helper::getSetting('privacy_url', '') : '';
$_imprintUrl = $_dbReady ? Helper::getSetting('imprint_url', '') : '';
?>
<body class="auth-body">
<div class="auth-wrapper">
    <div class="auth-card">
        <div class="auth-logo">
            <svg viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" width="40" height="40">
                <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><?= Helper::e($_appName) ?></span>
        </div>
        <?= $content ?>
    </div>
    <footer class="auth-footer">
        <div class="auth-footer-left">
            <?php if (PluginManager::filter('show_powered_by', true)): ?>
            <a href="https://plenvo.gp-server.com" target="_blank" rel="noopener"><?= t('powered_by_plenvo') ?></a>
            <?php endif; ?>
        </div>
        <?php if ($_privacyUrl || $_imprintUrl): ?>
        <div class="auth-footer-right">
            <?php if ($_privacyUrl): ?>
            <a href="<?= Helper::e($_privacyUrl) ?>" target="_blank" rel="noopener"><?= t('privacy_policy') ?></a>
            <?php endif; ?>
            <?php if ($_privacyUrl && $_imprintUrl): ?>
            <span class="footer-sep">·</span>
            <?php endif; ?>
            <?php if ($_imprintUrl): ?>
            <a href="<?= Helper::e($_imprintUrl) ?>" target="_blank" rel="noopener"><?= t('imprint') ?></a>
            <?php endif; ?>
        </div>
        <?php endif; ?>
    </footer>
</div>
<script nonce="<?= csp_nonce() ?>" src="/assets/js/app.js?v=<?= APP_VERSION ?>"></script>
</body>
</html>
