{% extends "service_monitor/base.html" %}
{% block title %}巡检报告{% endblock %}

{% block extra_css %}
<style>
    /* 筛选栏 */
    .filter-bar {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 16px;
    }
    .filter-bar select {
        padding: 8px 12px;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        font-size: 14px;
        color: var(--gray-700);
        background: #fff;
    }
    .filter-bar select:focus {
        outline: none;
        border-color: var(--primary);
    }
    .report-count {
        font-size: 13px;
        color: var(--gray-500);
        margin-left: auto;
    }

    /* 报告列表 */
    .report-list {
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,.06);
        border: 1px solid var(--gray-200);
    }
    .report-row {
        display: grid;
        grid-template-columns: 2fr 1fr 2fr 2fr 1fr;
        gap: 12px;
        align-items: center;
        padding: 14px 18px;
        border-bottom: 1px solid var(--gray-100);
        text-decoration: none;
    }
    .report-row:last-child { border-bottom: none; }
    .report-row:hover { background: var(--gray-50); }
    .report-target { font-weight: 600; color: var(--gray-900); }
    .report-suite { font-size: 13px; color: var(--gray-500); }
    .report-summary { display: flex; gap: 10px; font-size: 13px; }
    .sm-ok { color: var(--green); } .sm-warn { color: var(--yellow); } .sm-crit { color: var(--red); }
    .report-time { font-size: 13px; color: var(--gray-500); }
    .btn-view {
        background: var(--gray-100);
        color: var(--gray-700);
        padding: 6px 14px;
        border-radius: 6px;
        font-size: 13px;
        font-weight: 600;
        text-decoration: none;
        text-align: center;
    }
    .btn-view:hover { background: var(--gray-200); }

    @media screen and (max-width: 768px) {
        .report-row { grid-template-columns: 1fr 1fr; gap: 6px; }
        .report-summary { font-size: 12px; }
        .filter-bar { flex-wrap: wrap; }
    }
</style>
{% endblock %}

{% block content %}
<div class="section-head">
    <div class="section-title">📋 巡检报告</div>
</div>

<div class="filter-bar">
    <select id="filter-target" onchange="filterByTarget()">
        <option value="">全部目标</option>
        {% for t in targets %}
        <option value="{{ t.id }}" {{ 'selected' if request.args.get('target_id') == t.id }}>{{ t.name }}</option>
        {% endfor %}
    </select>
    <span class="report-count">共 {{ reports | length }} 条报告</span>
</div>

{% if reports %}
<div class="report-list">
    {% for r in reports %}
    <a href="/service-monitor/report/{{ r.id }}" class="report-row">
        <span class="report-target">{{ r.target_name }}</span>
        <span class="report-suite">{{ '快速' if r.suite == 'quick' else '全量' }}</span>
        <span class="report-summary">
            <span class="sm-ok">✓{{ r.summary.正常 if r.summary else 0 }}</span>
            <span class="sm-warn">⚠{{ r.summary.警告 if r.summary else 0 }}</span>
            <span class="sm-crit">✗{{ r.summary.严重 if r.summary else 0 }}</span>
        </span>
        <span class="report-time">{{ (r.started_at or '')[5:16].replace('T', ' ') }}</span>
        <span class="btn-view">查看</span>
    </a>
    {% endfor %}
</div>
{% else %}
<div class="empty">📭 暂无巡检报告，点击目标卡片开始巡检</div>
{% endif %}
{% endblock %}

{% block extra_js %}
<script>
    function filterByTarget() {
        const targetId = document.getElementById('filter-target').value;
        const url = targetId
            ? '/service-monitor/reports?target_id=' + encodeURIComponent(targetId)
            : '/service-monitor/reports';
        window.location.href = url;
    }
</script>
{% endblock %}