<?php
require __DIR__ . '/../../app/bootstrap.php';
require __DIR__ . '/../../app/database.php';
require_login();

$activeNav = 'plugins';
$pageTitle = '插件开发规范';

require __DIR__ . '/../../app/admin-sidebar.php';
$adminName = isset($_SESSION['admin_name']) ? (string)$_SESSION['admin_name'] : 'Admin';
$adminUsername = isset($_SESSION['admin_username']) ? (string)$_SESSION['admin_username'] : 'admin';
$avatarText = strtoupper(substr($adminName !== '' ? $adminName : 'A', 0, 1));
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo e($pageTitle); ?> - <?php echo e(APP_NAME); ?></title>
<link rel="stylesheet" href="/assets/css/admin-ui.css">
<style>
.tab-nav{display:flex;gap:8px;margin-bottom:18px}
.tab-nav a{padding:8px 16px;border-radius:6px;font-size:13px;font-weight:500;text-decoration:none;color:#6b7280;background:#f3f4f6}
.tab-nav a.active{background:#4f46e5;color:#fff}
.doc-frame{width:100%;border:none;border-radius:12px;min-height:calc(100vh - 200px);background:#fff;box-shadow:0 2px 8px rgba(0,0,0,.04)}
</style>
</head>
<body>
<div class="admin-shell">
<?php render_admin_sidebar($activeNav, $adminName, $adminUsername, $avatarText); ?>
<main class="admin-content">
<div class="content-wrap">
    <h2 style="font-size:20px;font-weight:700;color:#1a1a2e;margin-bottom:6px;">插件管理</h2>
    <div class="tab-nav">
        <a href="/admin/plugin/list.php">本地插件</a>
        <a href="/admin/plugin/market.php">插件市场</a>
        <a href="/admin/plugin/doc.php" class="active">开发规范</a>
    </div>
    <?php
        $docPath = BASE_PATH . '/plugins/plugins-doc.html';
        if (is_file($docPath)) {
            $docHtml = file_get_contents($docPath);
            // 提取 <body> 内容，避免嵌套整个页面
            if (preg_match('/<body[^>]*>(.*)<\/body>/is', $docHtml, $bodyMatch)) {
                $docBody = $bodyMatch[1];
            } else {
                $docBody = $docHtml;
            }
            // 提取 <style> 标签内容
            $docStyles = '';
            if (preg_match_all('/<style[^>]*>(.*?)<\/style>/is', $docHtml, $styleMatches)) {
                $docStyles = implode("\n", $styleMatches[1]);
            }
            echo '<style>' . $docStyles . '</style>';
            echo '<div class="plugin-doc-content">' . $docBody . '</div>';
        } else {
            echo '<div style="padding:40px;text-align:center;color:#94a3b8;">文档文件不存在</div>';
        }
    ?>
</div>
</main>
</div>
</body>
</html>
