<?php
/**
 * Optional production-ready admin header component.
 * This is provided now so the admin area can move toward a shared layout during
 * the enterprise infrastructure build without breaking the current helper-based pages.
 */

if (file_exists(__DIR__ . '/admin_sidebar.php')) {
    require_once __DIR__ . '/admin_sidebar.php';
}

if (!function_exists('admin_header_render')) {
    function admin_header_render(string $title = 'Admin', string $subtitle = '', string $activeKey = ''): void
    {
        if (!function_exists('e')) {
            function e($value) { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); }
        }
        ?>
        <style>
            .admin-layout-shell{min-height:100vh;background:#f4f7fb;color:#0f172a;font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;display:grid;grid-template-columns:280px minmax(0,1fr)}
            .admin-sidebar-shell{background:#020617;color:#e5e7eb;padding:22px;position:sticky;top:0;height:100vh;overflow:auto}.admin-sidebar-brand{font-size:22px;font-weight:950;letter-spacing:-.04em;margin-bottom:22px}.admin-sidebar-nav{display:grid;gap:7px}.admin-sidebar-link{display:block;color:#cbd5e1;text-decoration:none;padding:11px 12px;border-radius:13px;font-weight:800;font-size:13px}.admin-sidebar-link:hover,.admin-sidebar-link.is-active{background:#1d4ed8;color:#fff}.admin-main-shell{min-width:0}.admin-topbar-shell{background:#fff;border-bottom:1px solid #e2e8f0;padding:22px 28px;display:flex;justify-content:space-between;gap:18px;align-items:center}.admin-page-title{font-size:28px;font-weight:950;letter-spacing:-.04em}.admin-page-subtitle{margin-top:5px;color:#64748b;font-size:13px}.admin-content-shell{padding:28px}@media(max-width:980px){.admin-layout-shell{grid-template-columns:1fr}.admin-sidebar-shell{position:relative;height:auto}.admin-topbar-shell{align-items:flex-start;flex-direction:column}}
        </style>
        <div class="admin-layout-shell">
            <?php if (function_exists('admin_sidebar_render')) admin_sidebar_render($activeKey); ?>
            <main class="admin-main-shell">
                <header class="admin-topbar-shell">
                    <div>
                        <div class="admin-page-title"><?= e($title) ?></div>
                        <?php if ($subtitle !== ''): ?><div class="admin-page-subtitle"><?= e($subtitle) ?></div><?php endif; ?>
                    </div>
                    <a href="control_panel.php" style="background:#2563eb;color:#fff;text-decoration:none;border-radius:12px;padding:10px 14px;font-weight:900;font-size:13px;">Control Panel</a>
                </header>
                <section class="admin-content-shell">
        <?php
    }
}

if (!function_exists('admin_header_footer')) {
    function admin_header_footer(): void
    {
        echo '</section></main></div>';
    }
}
