<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>接收日志 - 短信转发接收端</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            animation: slideInDown 0.5s ease-out;
        }

        .header h1 {
            font-size: 24px;
            color: #333;
        }

        .nav {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }

        .nav a {
            padding: 8px 16px;
            text-decoration: none;
            background: #667eea;
            color: white;
            border-radius: 5px;
            transition: background 0.3s;
        }

        .nav a:hover {
            background: #764ba2;
        }

        .nav a.active {
            background: #764ba2;
        }

        .nav .logout {
            background: #dc3545;
        }

        .nav .logout:hover {
            background: #c82333;
        }

        .toolbar {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
            flex-wrap: wrap;
            align-items: center;
            background: white;
            padding: 15px;
            border-radius: 10px;
            animation: fadeInUp 0.5s ease-out forwards;
            opacity: 0;
            animation-delay: 0.4s;
        }

        .auto-refresh-info {
            display: flex;
            align-items: center;
            gap: 10px;
            color: #666;
            font-size: 14px;
        }

        .refresh-toggle {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 5px 10px;
            background: #f0f0f0;
            border-radius: 5px;
            cursor: pointer;
            user-select: none;
        }

        .refresh-toggle.active {
            background: #d4edda;
            color: #155724;
        }

        .logs-list {
            background: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            animation: fadeInUp 0.5s ease-out forwards;
            opacity: 0;
            animation-delay: 0.5s;
        }

        .logs-list table {
            width: 100%;
            border-collapse: collapse;
        }

        .logs-list th, .logs-list td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        .logs-list th {
            background-color: #f8f9fa;
            font-weight: 600;
            color: #555;
        }

        .logs-list tr:hover {
            background-color: #f9f9f9;
        }

        .status-badge {
            display: inline-block;
            padding: 4px 10px;
            border-radius: 10px;
            font-size: 12px;
            font-weight: bold;
        }

        .status-badge.success {
            background: #d4edda;
            color: #155724;
        }

        .status-badge.error {
            background: #f8d7da;
            color: #721c24;
        }

        .sign-badge {
            font-size: 16px;
        }

        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            margin-top: 20px;
            padding: 20px;
            animation: fadeInUp 0.5s ease-out forwards;
            opacity: 0;
            animation-delay: 0.6s;
        }

        .pagination a, .pagination span {
            padding: 8px 12px;
            background: white;
            border-radius: 5px;
            text-decoration: none;
            color: #333;
        }

        .pagination a:hover {
            background: #667eea;
            color: white;
        }

        .pagination span.active {
            background: #667eea;
            color: white;
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #999;
        }

        .empty-state h3 {
            margin-bottom: 10px;
            color: #666;
        }

        @keyframes fadeInUp {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes slideInDown {
            from { opacity: 0; transform: translateY(-30px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @media (max-width: 768px) {
            .header { flex-direction: column; gap: 15px; }
            .nav { justify-content: center; }
            .toolbar { flex-direction: column; align-items: stretch; }
            .logs-list { overflow-x: auto; }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📋 接收日志</h1>
            <div class="nav">
                <a href="/">短信列表</a>
                <a href="/logs" class="active">接收日志</a>
                <a href="/statistics">统计信息</a>
                <a href="/logout" class="logout">退出登录</a>
            </div>
        </div>

        <div class="toolbar">
            <span style="color: #666;">自动刷新</span>
            <div class="auto-refresh-info">
                <span class="refresh-toggle active" id="refreshToggle">
                    <input type="checkbox" id="autoRefresh" checked onchange="toggleAutoRefresh()">
                    <span>启用</span>
                </span>
                <span id="refreshCountdown">30s</span>
            </div>
            <div class="refresh-btn">
                <button onclick="location.reload()">立即刷新</button>
            </div>
        </div>

        <div class="logs-list">
            {{if gt (len .logs) 0}}
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>号码</th>
                        <th>内容</th>
                        <th>时间</th>
                        <th>签名</th>
                        <th>状态</th>
                    </tr>
                </thead>
                <tbody>
                    {{range .logs}}
                    <tr>
                        <td>{{.ID}}</td>
                        <td>{{.FromNumber}}</td>
                        <td style="max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">{{.Content}}</td>
                        <td>{{.CreatedAt.Format "2006-01-02 15:04:05"}}</td>
                        <td>
                            {{if .SignValid.Valid}}
                                {{if .SignValid.Bool}}
                                <span class="sign-badge">✅</span>
                                {{else}}
                                <span class="sign-badge">❌</span>
                                {{end}}
                            {{else}}
                            <span style="color: #999;">-</span>
                            {{end}}
                        </td>
                        <td>
                            {{if eq .Status "success"}}
                            <span class="status-badge success">成功</span>
                            {{else}}
                            <span class="status-badge error">失败</span>
                            {{if .ErrorMessage.Valid}}
                            <br><small style="color: #e74c3c;">{{.ErrorMessage.String}}</small>
                            {{end}}
                            {{end}}
                        </td>
                    </tr>
                    {{end}}
                </tbody>
            </table>
            {{else}}
            <div class="empty-state">
                <h3>暂无日志</h3>
            </div>
            {{end}}
        </div>

        {{if gt .totalPages 1}}
        <div class="pagination">
            {{if gt .page 1}}
            <a href="/logs?page={{sub .page 1}}">上一页</a>
            {{end}}

            {{range $p := (seq 1 .totalPages)}}
                {{if eq $p $.page}}
                <span class="active">{{$p}}</span>
                {{else if or (le $p 3) (ge $p (sub $.totalPages 2)) (and (ge $p (sub $.page 1)) (le $p (add $.page 1)))}}
                <a href="/logs?page={{$p}}">{{$p}}</a>
                {{else if or (eq $p 4) (eq $p (sub $.totalPages 2))}}
                <span>...</span>
                {{end}}
            {{end}}

            {{if lt .page .totalPages}}
            <a href="/logs?page={{add .page 1}}">下一页</a>
            {{end}}

            <span>共 {{.total}} 条，第 {{.page}} / {{.totalPages}} 页</span>
        </div>
        {{end}}
    </div>

    <script>
        let refreshInterval;
        let countdownInterval;
        let refreshCountdown = 30;
        const REFRESH_INTERVAL = 30;

        function toggleAutoRefresh() {
            const checkbox = document.getElementById('autoRefresh');
            const toggle = document.getElementById('refreshToggle');
            if (checkbox.checked) {
                toggle.classList.add('active');
                startAutoRefresh();
            } else {
                toggle.classList.remove('active');
                stopAutoRefresh();
            }
        }

        function startAutoRefresh() {
            refreshCountdown = REFRESH_INTERVAL;
            updateCountdown();
            refreshInterval = setInterval(() => location.reload(), REFRESH_INTERVAL * 1000);
            countdownInterval = setInterval(() => {
                refreshCountdown--;
                updateCountdown();
            }, 1000);
        }

        function stopAutoRefresh() {
            clearInterval(refreshInterval);
            clearInterval(countdownInterval);
            document.getElementById('refreshCountdown').textContent = '--s';
        }

        function updateCountdown() {
            document.getElementById('refreshCountdown').textContent = refreshCountdown + 's';
        }

        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('autoRefresh').addEventListener('change', toggleAutoRefresh);
            startAutoRefresh();
        });
    </script>
</body>
</html>