<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard - Fixture Manager</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .header {
            background-color: #007bff;
            color: white;
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .logo {
            font-size: 1.5rem;
            font-weight: bold;
        }
        .nav {
            display: flex;
            gap: 1rem;
        }
        .nav a {
            color: white;
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 4px;
            transition: background-color 0.3s;
        }
        .nav a:hover {
            background-color: rgba(255,255,255,0.1);
        }
        .container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 2rem;
        }
        .welcome {
            background: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 2rem;
        }
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }
        .stat-card {
            background: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            text-align: center;
        }
        .stat-number {
            font-size: 2rem;
            font-weight: bold;
            color: #007bff;
            margin-bottom: 0.5rem;
        }
        .stat-label {
            color: #666;
            font-size: 0.9rem;
        }
        .recent-section {
            background: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 2rem;
        }
        .section-title {
            font-size: 1.2rem;
            font-weight: bold;
            margin-bottom: 1rem;
            color: #333;
        }
        .item-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .item-list li {
            padding: 0.5rem 0;
            border-bottom: 1px solid #eee;
        }
        .item-list li:last-child {
            border-bottom: none;
        }
        .alert {
            padding: 12px;
            margin-bottom: 1rem;
            border-radius: 4px;
        }
        .alert-error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .alert-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .btn {
            display: inline-block;
            padding: 8px 16px;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-size: 0.9rem;
            transition: background-color 0.3s;
        }
        .btn:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="logo">🥊 Fixture Manager</div>
        <div class="nav">
            <a href="{{ url_for('main.dashboard') }}">Dashboard</a>
            <a href="{{ url_for('main.fixtures') }}">Fixtures</a>
            <a href="{{ url_for('main.uploads') }}">Uploads</a>
            <a href="{{ url_for('main.statistics') }}">Statistics</a>
            {% if current_user.is_admin %}
                <a href="{{ url_for('main.admin_panel') }}">Admin</a>
            {% endif %}
            <a href="{{ url_for('auth.logout') }}">Logout</a>
        </div>
    </div>

    <div class="container">
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ 'error' if category == 'error' else 'success' }}">
                        {{ message }}
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <div class="welcome">
            <h1>Welcome back, {{ current_user.username }}!</h1>
            <p>Here's an overview of your fixture management activity.</p>
        </div>

        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-number">{{ user_matches or 0 }}</div>
                <div class="stat-label">Your Matches</div>
            </div>
            <div class="stat-card">
                <div class="stat-number">{{ user_uploads or 0 }}</div>
                <div class="stat-label">Your Uploads</div>
            </div>
            {% if current_user.is_admin and system_stats %}
                <div class="stat-card">
                    <div class="stat-number">{{ system_stats.get('total_matches', 0) }}</div>
                    <div class="stat-label">Total System Matches</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">{{ system_stats.get('total_users', 0) }}</div>
                    <div class="stat-label">Total Users</div>
                </div>
            {% endif %}
        </div>

        {% if recent_fixtures %}
        <div class="recent-section">
            <div class="section-title">Recent Fixtures</div>
            <ul class="item-list">
                {% for fixture in recent_fixtures %}
                <li>
                    <strong>{{ fixture.filename }}</strong>:
                    {{ fixture.match_count }} matches
                    <span style="float: right;">
                        <a href="{{ url_for('main.fixture_detail', fixture_id=fixture.fixture_id) }}" class="btn">View</a>
                    </span>
                </li>
                {% endfor %}
            </ul>
            <div style="margin-top: 1rem;">
                <a href="{{ url_for('main.fixtures') }}" class="btn">View All Fixtures</a>
            </div>
        </div>
        {% endif %}

        <div class="recent-section">
            <div class="section-title">Quick Actions</div>
            <div style="display: flex; gap: 1rem; flex-wrap: wrap;">
                <a href="{{ url_for('upload.upload_fixture') }}" class="btn">Upload Fixture File</a>
                <a href="{{ url_for('main.fixtures') }}" class="btn">Browse Fixtures</a>
                <a href="{{ url_for('main.statistics') }}" class="btn">View Statistics</a>
            </div>
        </div>
    </div>
</body>
</html>