<?php
/// file: app/View/layouts/admin.php

declare(strict_types=1);

/** @var string $content */
/** @var \App\Core\App $app */
$brand = (string) $app->config('app.name', 'SANEKSA');

$requestPath = \App\Core\Request::fromGlobals()->uri();
if ($requestPath !== '/' && str_ends_with($requestPath, '/')) {
    $requestPath = rtrim($requestPath, '/') ?: '/';
}

$navActive = static function (string $href) use ($requestPath): bool {
    $href = '/' . ltrim($href, '/');
    if ($href === '/admin') {
        return $requestPath === '/admin';
    }

    return $requestPath === $href || str_starts_with($requestPath, $href . '/');
};

/** @var list<array{href:string,label:string}> $adminNav */
$adminNav = [
    ['href' => '/admin', 'label' => 'Dashboard'],
    ['href' => '/admin/projects', 'label' => 'Projects'],
    ['href' => '/admin/media', 'label' => 'Site media'],
    ['href' => '/admin/journal', 'label' => 'Journal'],
    ['href' => '/admin/services', 'label' => 'Services'],
    ['href' => '/admin/contacts', 'label' => 'Contacts'],
    ['href' => '/admin/careers', 'label' => 'Careers'],
    ['href' => '/admin/applications', 'label' => 'Applications'],
    ['href' => '/admin/settings', 'label' => 'Site settings'],
    ['href' => '/admin/seo', 'label' => 'SEO'],
];
?>
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="robots" content="noindex,nofollow">
    <title>Admin — <?= e($brand) ?></title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=Instrument+Serif:ital@0;1&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= e(asset('css/main.css')) ?>">
    <link rel="stylesheet" href="<?= e(asset('css/admin-shell.css')) ?>">
</head>
<body class="admin-shell min-h-screen bg-carbon text-smoke-100 antialiased">
<div class="admin-shell-bg" aria-hidden="true"></div>
<div class="admin-shell-inner relative z-10 flex min-h-screen flex-col lg:flex-row">
    <div class="admin-main flex min-h-0 flex-1 flex-col overflow-auto px-5 py-8 sm:px-8 sm:py-10 lg:px-12 lg:py-12">
        <?= $content ?>
    </div>
    <aside
        class="relative flex w-full shrink-0 flex-col border-t border-white/[0.08] bg-[#0c0c0e]/[0.65] backdrop-blur-2xl lg:h-screen lg:w-[17.5rem] lg:border-l lg:border-t-0 lg:shadow-[-24px_0_80px_rgba(0,0,0,0.35)]"
    >
        <div
            class="admin-sidebar-glow pointer-events-none absolute bottom-0 left-0 top-0 w-px bg-gradient-to-b from-transparent via-electric-400/50 to-transparent opacity-60"
            aria-hidden="true"
        ></div>
        <div class="flex flex-col px-5 py-6 sm:px-6 lg:flex-1 lg:overflow-y-auto lg:px-6 lg:py-8">
            <a
                href="<?= e(url('/admin')) ?>"
                class="group inline-flex items-center gap-3 focus:outline-none focus-visible:ring-2 focus-visible:ring-electric-400/40 focus-visible:ring-offset-2 focus-visible:ring-offset-carbon"
                aria-label="<?= e($brand) ?>"
            >
                <?php \App\Core\View::component('site-logo', [
                    'brand' => $brand,
                    'class' => 'h-8 w-auto opacity-95 transition duration-300 group-hover:opacity-100 group-hover:drop-shadow-[0_0_20px_rgba(56,189,248,0.25)]',
                ]); ?>
            </a>
            <p class="muted-label mt-8">Control</p>
            <nav class="mt-4 space-y-0.5 text-[0.8125rem] font-medium leading-snug tracking-wide" aria-label="Admin">
                <?php foreach ($adminNav as $item): ?>
                    <?php
                    $active = $navActive($item['href']);
                    $base = 'relative flex items-center rounded-lg px-3 py-2.5 transition duration-200 ease-out';
                    $idle = 'text-silver-400 hover:bg-white/[0.04] hover:text-white';
                    $on = 'bg-white/[0.06] text-white shadow-[inset_0_0_0_1px_rgba(255,255,255,0.06),0_0_24px_rgba(14,165,233,0.08)]';
                    ?>
                    <a
                        class="<?= e($base . ' ' . ($active ? $on : $idle)) ?>"
                        href="<?= e(url($item['href'])) ?>"
                        <?php if ($active): ?>aria-current="page"<?php endif; ?>
                    >
                        <?php if ($active): ?>
                            <span
                                class="absolute left-0 top-1/2 h-5 w-0.5 -translate-y-1/2 rounded-full bg-gradient-to-b from-electric-300 to-violet-400 shadow-[0_0_12px_rgba(56,189,248,0.6)]"
                                aria-hidden="true"
                            ></span>
                        <?php endif; ?>
                        <span class="<?= $active ? 'pl-2' : '' ?>"><?= e($item['label']) ?></span>
                    </a>
                <?php endforeach; ?>
            </nav>
            <div class="mt-8 space-y-0.5 border-t border-white/[0.06] pt-6 text-[0.8125rem]">
                <a
                    class="flex items-center rounded-lg px-3 py-2.5 text-silver-500 transition duration-200 hover:bg-white/[0.04] hover:text-electric-300"
                    href="<?= e(url('/')) ?>"
                    target="_blank"
                    rel="noopener"
                >View site</a>
                <a
                    class="flex items-center rounded-lg px-3 py-2.5 text-silver-500 transition duration-200 hover:bg-red-400/10 hover:text-red-300"
                    href="<?= e(url('/admin/logout')) ?>"
                >Logout</a>
            </div>
        </div>
    </aside>
</div>
</body>
</html>
