<?php
/** @var string $content */
use Core\Theme;
$seg = $seg ?? '';
if ($seg === '') {
    $__p = trim(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH), '/');
    $__parts = explode('/', $__p);
    $seg = $__parts[1] ?? '';
}
$site = Theme::get('site_name', '酷冰甲 · 降温服');
$nav = admin_nav_items();
?>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>后台管理 · <?php echo e($site); ?></title>
    <link rel="stylesheet" href="<?php echo asset('css/admin.css'); ?>">
</head>
<body class="admin">
<?php if (is_admin()): ?>
    <aside class="admin-side">
        <a class="admin-brand" href="<?php echo site_url('admin'); ?>"><span class="brand-mark"><?php echo admin_icon('snowflake', 20); ?></span> <span class="brand-text"><?php echo e($site); ?></span></a>
        <nav class="admin-nav">
            <?php foreach ($nav as $n): ?>
                <a href="<?php echo site_url($n['url']); ?>" class="<?php echo $seg === $n['k'] ? 'active' : ''; ?>"><span class="nav-ic"><?php echo admin_icon($n['ic'] ?? 'file-text', 20); ?></span><span class="nav-label"><?php echo e($n['label']); ?></span><?php if (!empty($n['badge'])): ?><span class="nav-badge"><?php echo (int)$n['badge']; ?></span><?php endif; ?></a>
            <?php endforeach; ?>
        </nav>
        <div class="admin-side-foot">
            <a href="<?php echo site_url(); ?>" target="_blank"><?php echo admin_icon('globe', 18); ?> 查看前台</a>
        </div>
    </aside>
    <div class="admin-body">
        <header class="admin-top">
            <div class="admin-top-left">
                <button class="menu-toggle" aria-label="菜单"><?php echo admin_icon('menu', 22); ?></button>
                <a class="top-link" href="<?php echo site_url(); ?>" target="_blank"><?php echo admin_icon('globe', 16); ?> 查看前台</a>
            </div>
            <div class="admin-user">
                <span class="admin-user-name"><span class="admin-avatar"><?php echo admin_icon('user', 16); ?></span> <?php echo e($_SESSION['admin_name'] ?? '管理员'); ?>
                    <span class="role-badge role-<?php echo e(admin_role()); ?>"><?php echo e(admin_role_label(admin_role())); ?></span>
                </span>
                <a class="btn-soft btn-sm" href="<?php echo site_url('admin/password'); ?>"><?php echo admin_icon('key', 15); ?> 修改密码</a>
                <a class="btn-soft btn-sm" href="<?php echo site_url('admin/logout'); ?>"><?php echo admin_icon('logout', 15); ?> 退出</a>
            </div>
        </header>
        <main class="admin-content">
        <?php if (!empty($_SESSION['flash'])): $f = $_SESSION['flash']; unset($_SESSION['flash']); ?>
            <div class="alert alert-<?php echo $f['type'] === 'ok' ? 'ok' : 'err'; ?>"><?php echo e($f['msg']); ?></div>
        <?php endif; ?>
        <?php echo $content; ?></main>
    </div>
<?php else: ?>
    <div class="admin-login-wrap"><?php echo $content; ?></div>
<?php endif; ?>
<script src="<?php echo asset('js/admin.js'); ?>"></script>
</body>
</html>
