<?php
require __DIR__ . '/../../app/bootstrap.php';
require __DIR__ . '/../../app/database.php';
require_once __DIR__ . '/../../app/template-pack.php';
require __DIR__ . '/../../app/admin-sidebar.php';
require_login();

$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));

$stats = array(
    'domain_total' => 0,
    'domain_enabled' => 0,
    'domain_root_ok' => 0,
    'menu_total' => 0,
    'template_total' => 0,
    'template_enabled' => 0,
    'content_total' => 0,
    'content_published' => 0,
    'content_draft' => 0,
    'ad_total' => 0,
    'ad_enabled' => 0,
    'ai_model_total' => 0,
    'ai_model_enabled' => 0,
    'admin_enabled' => 0,
    'task_total' => 0,
    'task_running' => 0,
    'task_success_keywords' => 0,
    'task_failed_keywords' => 0
);
$recentTasks = array();
$recentContents = array();
$recentModels = array();
$domains = array();
$dashboardError = '';

try {
    $pdo = db_connection();

    if (table_exists('domains')) {
        ensure_domains_table_has_site_root();
        $uid = current_user_id();
        $dStmt = $pdo->prepare('SELECT * FROM domains WHERE user_id = :uid ORDER BY id DESC');
        $dStmt->execute(array(':uid' => $uid));
        $domains = $dStmt->fetchAll(PDO::FETCH_ASSOC);
        $stats['domain_total'] = count($domains);
        foreach ($domains as $domain) {
            if (isset($domain['status']) && $domain['status'] === 'enabled') {
                $stats['domain_enabled']++;
            }
            $rootStatus = check_domain_site_root_status($domain);
            if (!empty($rootStatus['ok'])) {
                $stats['domain_root_ok']++;
            }
        }
    }

    if (table_exists('menus')) {
        $menus = list_menus(0, '');
        $stats['menu_total'] = count($menus);
    }

    $packs = list_template_packs();
    $stats['template_total'] = count($packs);
    $stats['template_enabled'] = count($packs);

    if (table_exists('contents')) {
        $contents = list_contents('', '', 0, 0);
        $stats['content_total'] = count($contents);
        foreach ($contents as $content) {
            $status = isset($content['status']) ? (string)$content['status'] : '';
            if ($status === 'published') {
                $stats['content_published']++;
            }
            if ($status === 'draft') {
                $stats['content_draft']++;
            }
        }
        $recentContents = array_slice($contents, 0, 6);
    }

    if (table_exists('article_ads')) {
        $ads = list_article_ads('', '');
        $stats['ad_total'] = count($ads);
        foreach ($ads as $ad) {
            if (isset($ad['status']) && $ad['status'] === 'enabled') {
                $stats['ad_enabled']++;
            }
        }
    }

    if (table_exists('ai_models')) {
        $models = list_ai_models('', '');
        $stats['ai_model_total'] = count($models);
        foreach ($models as $model) {
            if (isset($model['status']) && $model['status'] === 'enabled') {
                $stats['ai_model_enabled']++;
            }
        }
        $recentModels = array_slice($models, 0, 4);
    }

    if (table_exists('admins') && is_super_admin()) {
        $stats['admin_enabled'] = enabled_admin_count();
    }

    if (table_exists('article_generation_tasks')) {
        $tasks = list_article_generation_tasks('', '');
        $stats['task_total'] = count($tasks);
        foreach ($tasks as $task) {
            $taskStatus = isset($task['status']) ? (string)$task['status'] : '';
            if ($taskStatus === 'running') {
                $stats['task_running']++;
            }
            $stats['task_success_keywords'] += isset($task['success_keyword_count']) ? (int)$task['success_keyword_count'] : 0;
            $stats['task_failed_keywords'] += isset($task['failed_keyword_count']) ? (int)$task['failed_keyword_count'] : 0;
        }
        $recentTasks = array_slice($tasks, 0, 5);
    }
} catch (Exception $e) {
    $dashboardError = $e->getMessage();
}

$spiderDaily = array();
$spiderSummary = array();
$dashSpiderDomains = is_super_admin() ? null : user_domain_names();
try {
    if (table_exists('spider_daily')) {
        $spiderDaily = spider_daily_stats(7, '', $dashSpiderDomains);
        $spiderSummary = spider_summary_stats(7, '', $dashSpiderDomains);
    }
} catch (Exception $e) {}

$spiderChartDays = array();
$spiderChartSeries = array();
if (!empty($spiderDaily)) {
    $daySet = array();
    $spiderSet = array();
    foreach ($spiderDaily as $row) {
        $daySet[$row['day']] = true;
        $spiderSet[$row['spider_name']] = true;
    }
    $spiderChartDays = array_keys($daySet);
    sort($spiderChartDays);
    foreach (array_keys($spiderSet) as $sn) {
        $data = array();
        foreach ($spiderChartDays as $d) {
            $found = 0;
            foreach ($spiderDaily as $row) {
                if ($row['day'] === $d && $row['spider_name'] === $sn) {
                    $found = (int)$row['hits'];
                    break;
                }
            }
            $data[] = $found;
        }
        $spiderChartSeries[] = array('name' => $sn, 'data' => $data);
    }
}

$contentStats = array('site_total' => 0, 'site_today' => 0, 'article_total' => 0, 'article_today' => 0);
try { if (table_exists('contents')) { $contentStats = count_content_stats(); } } catch (Exception $e) {}

$publishRate = $stats['content_total'] > 0 ? round(($stats['content_published'] / $stats['content_total']) * 100) : 0;
$templateCoverage = $stats['template_total'] > 0 ? round(($stats['template_enabled'] / $stats['template_total']) * 100) : 0;
$modelReadyRate = $stats['ai_model_total'] > 0 ? round(($stats['ai_model_enabled'] / $stats['ai_model_total']) * 100) : 0;
?><!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(APP_NAME); ?> - 后台仪表盘</title>
    <link rel="stylesheet" href="/assets/css/admin-ui.css">
</head>
<body>
<div class="admin-shell dash-theme">
    <?php render_admin_sidebar('dashboard', $adminName, $adminUsername, $avatarText); ?>
    <main class="admin-content">
        <div class="content-wrap dash-wrap">

            <?php if (!is_super_admin() && (isset($_GET['license_error']) || !license_is_activated() || license_is_expired())): ?>
            <div style="background:#fef2f2;border:1px solid #fecaca;border-radius:10px;padding:18px 20px;margin-bottom:20px;text-align:center;">
                <p style="margin:0;font-size:16px;font-weight:700;color:#991b1b;">⚠ 系统授权未激活或已过期</p>
                <p style="margin:6px 0 0;font-size:13px;color:#991b1b;">部分功能已锁定，请联系超级管理员处理授权问题。</p>
            </div>
            <?php endif; ?>

            <header class="dash-hero">
                <div class="dash-hero__grid"></div>
                <div class="dash-hero__glow"></div>
                <div class="dash-hero__content">
                    <div class="dash-hero__copy">
                        <span class="dash-eyebrow"><i class="dot"></i>运营总览 · <?php echo e(date('Y-m-d H:i')); ?></span>
                        <h1>欢迎回来，<span class="accent"><?php echo e($adminName); ?></span></h1>
                        <p>聚焦 AI 批量建站全流程：域名接入、模板配置、内容生成、静态发布与模型调度。此处可快速查看整体健康度并进入关键模块。</p>
                        <div class="dash-hero__actions">
                            <a class="dash-btn dash-btn--primary" href="/admin/site-build/index.php"><span>+ 新建建站任务</span></a>
                            <a class="dash-btn dash-btn--ghost" href="/admin/content/list.php">内容管理</a>
                            <a class="dash-btn dash-btn--ghost" href="/admin/ai-model/list.php">AI 模型</a>
                        </div>
                    </div>
                    <div class="dash-hero__stats">
                        <div class="dash-hero__stat">
                            <span class="dash-hero__stat-label">已接入域名</span>
                            <strong class="dash-hero__stat-value"><?php echo number_format($stats['domain_total']); ?></strong>
                            <em class="dash-hero__stat-sub">可发布站点 <?php echo number_format($stats['domain_root_ok']); ?></em>
                            <span class="dash-hero__stat-bar"><i style="width: <?php echo $stats['domain_total'] > 0 ? min(100, round($stats['domain_root_ok'] / $stats['domain_total'] * 100)) : 0; ?>%"></i></span>
                        </div>
                        <div class="dash-hero__stat">
                            <span class="dash-hero__stat-label">内容发布率</span>
                            <strong class="dash-hero__stat-value"><?php echo e($publishRate); ?><small>%</small></strong>
                            <em class="dash-hero__stat-sub">已发布 <?php echo number_format($stats['content_published']); ?> / <?php echo number_format($stats['content_total']); ?></em>
                            <span class="dash-hero__stat-bar"><i style="width: <?php echo (int)$publishRate; ?>%"></i></span>
                        </div>
                        <div class="dash-hero__stat">
                            <span class="dash-hero__stat-label">模型可用率</span>
                            <strong class="dash-hero__stat-value"><?php echo e($modelReadyRate); ?><small>%</small></strong>
                            <em class="dash-hero__stat-sub">启用 <?php echo number_format($stats['ai_model_enabled']); ?> / <?php echo number_format($stats['ai_model_total']); ?></em>
                            <span class="dash-hero__stat-bar"><i style="width: <?php echo (int)$modelReadyRate; ?>%"></i></span>
                        </div>
                    </div>
                </div>
            </header>

            <?php if ($dashboardError !== ''): ?>
                <div class="dash-alert">
                    <strong>仪表盘数据加载异常</strong>
                    <span><?php echo e($dashboardError); ?></span>
                </div>
            <?php endif; ?>

            <section class="dash-kpi-grid">
                <?php
                $kpis = array(
                    array('域名总数', number_format($stats['domain_total']), '启用 ' . number_format($stats['domain_enabled']) . ' · 可写 ' . number_format($stats['domain_root_ok']), 'domain'),
                    array('模板总数', number_format($stats['template_total']), '启用覆盖率 ' . $templateCoverage . '%', 'template'),
                    array('内容总数', number_format($stats['content_total']), '已发布 ' . number_format($stats['content_published']) . ' · 草稿 ' . number_format($stats['content_draft']), 'content'),
                    array('生成任务', number_format($stats['task_total']), '运行中 ' . number_format($stats['task_running']) . ' · 成功 ' . number_format($stats['task_success_keywords']), 'task'),
                );
                foreach ($kpis as $kpi): ?>
                    <article class="dash-kpi" data-type="<?php echo e($kpi[3]); ?>">
                        <span class="dash-kpi__label"><?php echo e($kpi[0]); ?></span>
                        <strong class="dash-kpi__value"><?php echo $kpi[1]; ?></strong>
                        <span class="dash-kpi__meta"><?php echo e($kpi[2]); ?></span>
                        <span class="dash-kpi__spark"></span>
                    </article>
                <?php endforeach; ?>
            </section>

            <section class="dash-kpi-grid" style="margin-top:0;">
                <article class="dash-kpi" data-type="site-today">
                    <span class="dash-kpi__label">今日生成站点</span>
                    <strong class="dash-kpi__value"><?php echo number_format($contentStats['site_today']); ?></strong>
                    <span class="dash-kpi__meta">今日新增首页 / 站点内容</span>
                    <span class="dash-kpi__spark"></span>
                </article>
                <article class="dash-kpi" data-type="site-total">
                    <span class="dash-kpi__label">站点总数</span>
                    <strong class="dash-kpi__value"><?php echo number_format($contentStats['site_total']); ?></strong>
                    <span class="dash-kpi__meta">累计首页 / 站点内容</span>
                    <span class="dash-kpi__spark"></span>
                </article>
                <article class="dash-kpi" data-type="article-today">
                    <span class="dash-kpi__label">今日生成文章</span>
                    <strong class="dash-kpi__value"><?php echo number_format($contentStats['article_today']); ?></strong>
                    <span class="dash-kpi__meta">今日新增文章内容</span>
                    <span class="dash-kpi__spark"></span>
                </article>
                <article class="dash-kpi" data-type="article-total">
                    <span class="dash-kpi__label">文章总数</span>
                    <strong class="dash-kpi__value"><?php echo number_format($contentStats['article_total']); ?></strong>
                    <span class="dash-kpi__meta">累计文章内容</span>
                    <span class="dash-kpi__spark"></span>
                </article>
            </section>

            <section class="dash-quick">
                <?php
                $quick = array(
                    array('/admin/ai-model/list.php', 'AI 模型', '配置模型、密钥与可用性'),
                    array('/admin/template-pack/list.php', '模板套件', '管理统一风格模板套件'),
                    array('/admin/domain/list.php', '域名管理', '检查接入状态与站点目录'),
                    array('/admin/site-build/index.php', '一键建站', '发起首页或文章生成任务'),
                    array('/admin/content/list.php', '内容管理', '查看发布、草稿与静态页面'),
                    array('/admin/settings/index.php', '系统设置', '基础参数与安全项'),
                );
                foreach ($quick as $q): ?>
                    <a class="dash-quick__card" href="<?php echo e($q[0]); ?>">
                        <strong><?php echo e($q[1]); ?></strong>
                        <span><?php echo e($q[2]); ?></span>
                        <i class="dash-quick__arrow">→</i>
                    </a>
                <?php endforeach; ?>
            </section>

            <section class="dash-grid dash-grid--2">
                <article class="dash-panel">
                    <header class="dash-panel__head">
                        <div>
                            <h2>站点资产概览</h2>
                            <p>围绕建站所需的域名、栏目、模板、广告与账号做总览。</p>
                        </div>
                    </header>
                    <div class="dash-metric-list">
                        <div class="dash-metric"><span>栏目数量</span><strong><?php echo number_format($stats['menu_total']); ?></strong></div>
                        <div class="dash-metric"><span>广告位配置</span><strong><?php echo number_format($stats['ad_total']); ?> <em>/ 启用 <?php echo number_format($stats['ad_enabled']); ?></em></strong></div>
                        <div class="dash-metric"><span>AI 模型配置</span><strong><?php echo number_format($stats['ai_model_total']); ?> <em>/ 启用 <?php echo number_format($stats['ai_model_enabled']); ?></em></strong></div>
                        <?php if (is_super_admin()): ?>
                        <div class="dash-metric"><span>管理员账号</span><strong><?php echo number_format($stats['admin_enabled']); ?> <em>个启用</em></strong></div>
                        <?php endif; ?>
                    </div>
                </article>

                <article class="dash-panel">
                    <header class="dash-panel__head">
                        <div>
                            <h2>系统健康度</h2>
                            <p>快速确认核心链路是否具备上线条件。</p>
                        </div>
                    </header>
                    <div class="dash-health">
                        <?php
                        $healths = array(
                            array('域名根目录', $stats['domain_root_ok'] > 0, '可发布', '待检查'),
                            array('模板资源', $stats['template_enabled'] > 0, '已就绪', '未启用'),
                            array('模型资源', $stats['ai_model_enabled'] > 0, '已就绪', '未启用'),
                            array('发布内容', $stats['content_published'] > 0, '已有发布', '等待生成'),
                        );
                        foreach ($healths as $h): ?>
                            <div class="dash-health__row">
                                <span><?php echo e($h[0]); ?></span>
                                <b class="dash-pill <?php echo $h[1] ? 'is-ok' : 'is-warn'; ?>">
                                    <i></i><?php echo $h[1] ? e($h[2]) : e($h[3]); ?>
                                </b>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </article>
            </section>

            <section class="dash-panel">
                <header class="dash-panel__head">
                    <div>
                        <h2>蜘蛛抓取趋势</h2>
                        <p>近 7 天搜索引擎蜘蛛访问统计。</p>
                    </div>
                    <a class="dash-link" href="/admin/spider-stats/index.php">详细统计 →</a>
                </header>
                <?php if (!empty($spiderChartSeries)): ?>
                <div style="display:flex;gap:16px;margin-bottom:16px;flex-wrap:wrap;">
                    <?php
                    $spiderTotalHits = 0;
                    foreach ($spiderSummary as $ss) { $spiderTotalHits += (int)$ss['total_hits']; }
                    $spiderColors = array('Baidu' => '#3052e8', 'Google' => '#34a853', 'Bing' => '#00a4ef', 'Sogou' => '#ff6a00', '360Spider' => '#e63e30', 'Yandex' => '#ff0000', 'Other' => '#94a3b8');
                    foreach ($spiderSummary as $ss):
                        $sColor = isset($spiderColors[$ss['spider_name']]) ? $spiderColors[$ss['spider_name']] : '#6366f1';
                    ?>
                    <div style="flex:1;min-width:120px;background:#f8fafc;border-radius:12px;padding:14px 16px;border:1px solid #e2e8f0;">
                        <div style="font-size:12px;color:#94a3b8;margin-bottom:4px;display:flex;align-items:center;gap:6px;">
                            <i style="width:8px;height:8px;border-radius:50%;background:<?php echo $sColor; ?>;display:inline-block;"></i>
                            <?php echo e($ss['spider_name']); ?>
                        </div>
                        <strong style="font-size:22px;color:#1e293b;"><?php echo number_format((int)$ss['total_hits']); ?></strong>
                        <div style="font-size:11px;color:#94a3b8;margin-top:2px;">次抓取</div>
                    </div>
                    <?php endforeach; ?>
                </div>
                <div id="spiderChart" style="width:100%;height:260px;"></div>
                <?php else: ?>
                <div class="dash-empty">暂无蜘蛛抓取数据，蜘蛛访问站点后将自动记录。</div>
                <?php endif; ?>
            </section>

            <section class="dash-grid dash-grid--2">
                <article class="dash-panel">
                    <header class="dash-panel__head">
                        <div>
                            <h2>最近建站任务</h2>
                            <p>优先关注进行中和失败任务。</p>
                        </div>
                        <a class="dash-link" href="/admin/site-build/index.php">进入任务页 →</a>
                    </header>
                    <div class="dash-task-list">
                        <?php if (!empty($recentTasks)): ?>
                            <?php foreach ($recentTasks as $task):
                                $tStatus = isset($task['status']) ? (string)$task['status'] : 'unknown';
                                $pillClass = $tStatus === 'running' ? 'is-warn' : ($tStatus === 'enabled' ? 'is-ok' : 'is-info');
                            ?>
                                <div class="dash-task">
                                    <div class="dash-task__top">
                                        <strong><?php echo e(isset($task['task_name']) ? (string)$task['task_name'] : '未命名任务'); ?></strong>
                                        <b class="dash-pill <?php echo $pillClass; ?>"><i></i><?php echo e($tStatus); ?></b>
                                    </div>
                                    <p>模板 <em><?php echo e(isset($task['template_name']) ? (string)$task['template_name'] : '-'); ?></em> · 模型 <em><?php echo e(isset($task['model_name']) ? (string)$task['model_name'] : '-'); ?></em></p>
                                    <ul class="dash-task__meta">
                                        <li><span>域名</span><b><?php echo number_format(isset($task['domain_count']) ? (int)$task['domain_count'] : 0); ?></b></li>
                                        <li><span>关键词</span><b><?php echo number_format(isset($task['keyword_total']) ? (int)$task['keyword_total'] : 0); ?></b></li>
                                        <li><span>成功</span><b class="ok"><?php echo number_format(isset($task['success_keyword_count']) ? (int)$task['success_keyword_count'] : 0); ?></b></li>
                                        <li><span>失败</span><b class="danger"><?php echo number_format(isset($task['failed_keyword_count']) ? (int)$task['failed_keyword_count'] : 0); ?></b></li>
                                    </ul>
                                </div>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <div class="dash-empty">暂无建站任务，建议先创建一条首页或文章生成任务。</div>
                        <?php endif; ?>
                    </div>
                </article>

                <article class="dash-panel">
                    <header class="dash-panel__head">
                        <div>
                            <h2>最近动态</h2>
                            <p>从发布结果和模型配置两个维度回看近期动作。</p>
                        </div>
                    </header>
                    <div class="dash-split">
                        <div class="dash-split__col">
                            <h3 class="dash-subhead">最近内容</h3>
                            <?php if (!empty($recentContents)): ?>
                                <ul class="dash-timeline">
                                    <?php foreach ($recentContents as $content): ?>
                                        <li>
                                            <i class="dash-timeline__dot"></i>
                                            <strong><?php echo e(isset($content['title']) ? (string)$content['title'] : '未命名内容'); ?></strong>
                                            <span><?php echo e(isset($content['domain_name']) ? (string)$content['domain_name'] : '-'); ?> · <?php echo e(isset($content['path']) ? (string)$content['path'] : '-'); ?></span>
                                        </li>
                                    <?php endforeach; ?>
                                </ul>
                            <?php else: ?>
                                <div class="dash-empty">暂无内容记录。</div>
                            <?php endif; ?>
                        </div>
                        <div class="dash-split__col">
                            <h3 class="dash-subhead">最近模型</h3>
                            <?php if (!empty($recentModels)): ?>
                                <ul class="dash-timeline">
                                    <?php foreach ($recentModels as $model): ?>
                                        <li>
                                            <i class="dash-timeline__dot"></i>
                                            <strong><?php echo e(isset($model['name']) ? (string)$model['name'] : '未命名模型'); ?></strong>
                                            <span><?php echo e(isset($model['provider']) ? (string)$model['provider'] : '-'); ?> · <?php echo e(isset($model['model_name']) ? (string)$model['model_name'] : '-'); ?></span>
                                        </li>
                                    <?php endforeach; ?>
                                </ul>
                            <?php else: ?>
                                <div class="dash-empty">暂无模型配置。</div>
                            <?php endif; ?>
                        </div>
                    </div>
                </article>
            </section>

            <section class="dash-panel">
                <header class="dash-panel__head">
                    <div>
                        <h2>域名接入状态</h2>
                        <p>优先检查根目录是否存在且可写，这直接影响静态发布链路。</p>
                    </div>
                    <a class="dash-link" href="/admin/domain/list.php">管理域名 →</a>
                </header>
                <div class="dash-domain-grid">
                    <?php if (!empty($domains)): ?>
                        <?php foreach (array_slice($domains, 0, 6) as $domain): ?>
                            <?php $rootStatus = check_domain_site_root_status($domain); ?>
                            <div class="dash-domain">
                                <div class="dash-domain__top">
                                    <strong><?php echo e(isset($domain['domain']) ? (string)$domain['domain'] : '-'); ?></strong>
                                    <b class="dash-pill <?php echo !empty($rootStatus['ok']) ? 'is-ok' : 'is-warn'; ?>">
                                        <i></i><?php echo !empty($rootStatus['ok']) ? '可写' : '待处理'; ?>
                                    </b>
                                </div>
                                <p><?php echo e(isset($domain['site_name']) ? (string)$domain['site_name'] : '未设置站点名'); ?></p>
                                <small><?php echo e(isset($rootStatus['message']) ? (string)$rootStatus['message'] : ''); ?></small>
                            </div>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <div class="dash-empty">暂无域名接入记录。</div>
                    <?php endif; ?>
                </div>
            </section>

        </div>
    </main>
</div>
<script src="/assets/js/admin-ui.js"></script>
<?php if (!empty($spiderChartSeries)): ?>
<script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
<script>
(function(){
    var chartDom = document.getElementById('spiderChart');
    if (!chartDom) return;
    var chart = echarts.init(chartDom);
    var days = <?php echo json_encode(array_map(function($d){ return substr($d,5); }, $spiderChartDays)); ?>;
    var colorMap = {'Baidu':'#3052e8','Google':'#34a853','Bing':'#00a4ef','Sogou':'#ff6a00','360Spider':'#e63e30','Yandex':'#ff0000','Other':'#94a3b8'};
    var series = <?php echo json_encode($spiderChartSeries); ?>.map(function(s){
        return {
            name: s.name,
            type: 'line',
            smooth: true,
            symbol: 'circle',
            symbolSize: 6,
            lineStyle: { width: 2.5 },
            areaStyle: { opacity: 0.08 },
            itemStyle: { color: colorMap[s.name] || '#6366f1' },
            data: s.data
        };
    });
    chart.setOption({
        tooltip: { trigger:'axis', backgroundColor:'#1e293b', borderColor:'#334155', textStyle:{color:'#e2e8f0',fontSize:12} },
        legend: { bottom:0, textStyle:{color:'#64748b',fontSize:12}, icon:'circle', itemWidth:8, itemHeight:8 },
        grid: { top:16, right:16, bottom:40, left:46 },
        xAxis: { type:'category', data:days, axisLine:{lineStyle:{color:'#e2e8f0'}}, axisLabel:{color:'#94a3b8',fontSize:11}, axisTick:{show:false} },
        yAxis: { type:'value', minInterval:1, splitLine:{lineStyle:{color:'#f1f5f9'}}, axisLabel:{color:'#94a3b8',fontSize:11} },
        series: series
    });
    window.addEventListener('resize', function(){ chart.resize(); });
})();
</script>
<?php endif; ?>
</body>
</html>
