<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ app_name }} v{{ app_version }} - Hashtag Streams</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <!-- Favicon -->
    <link rel="icon" href="/static/FenLiu.png" type="image/png">
    <link rel="apple-touch-icon" href="/static/FenLiu.png">
</head>
<body class="bg-gray-50 min-h-screen">
    <nav class="bg-gradient-to-r from-blue-600 to-indigo-700 text-white shadow-lg">
        <div class="container mx-auto px-4 py-4">
            <div class="flex justify-between items-center">
                <div class="flex items-center space-x-4">
                    <div class="rounded-full p-2 bg-white/20">
                        <i class="fas fa-water text-2xl"></i>
                    </div>
                    <div>
                        <h1 class="text-2xl font-bold">{{ app_name }}</h1>
                        <p class="text-blue-100">分流 - Divide the Flow</p>
                    </div>
                </div>
                <div class="hidden md:flex space-x-6">
                    <a href="/" class="hover:text-blue-200 transition-colors">
                        <i class="fas fa-tachometer-alt mr-2"></i>Dashboard
                    </a>
                    <a href="/</div>streams" class="text-blue-200 font-semibold">
                        <i class="fas fa-hashtag mr-2"></i>Streams
                    </a>
                    <a href="/posts" class="hover:text-blue-200 transition-colors">
                        <i class="fas fa-stream mr-2"></i>Posts
                    </a>
                    <a href="/stats" class="hover:text-blue-200 transition-colors">
                        <i class="fas fa-chart-bar mr-2"></i>Stats
                    </a>
                </div>
                <button class="md:hidden text-2xl" onclick="toggleMobileMenu()">
                    <i class="fas fa-bars"></i>
                </button>
            </div>
            <div id="mobileMenu" class="hidden md:hidden mt-4 space-y-4">
                <a href="/" class="block hover:text-blue-200 transition-colors">
                    <i class="fas fa-tachometer-alt mr-2"></i>Dashboard
                </a>
                <a href="/streams" class="block text-blue-200 font-semibold">
                    <i class="fas fa-hashtag mr-2"></i>Streams
                </a>
                <a href="/posts" class="block hover:text-blue-200 transition-colors">
                    <i class="fas fa-stream mr-2"></i>Posts
                </a>
                <a href="/stats" class="block hover:text-blue-200 transition-colors">
                    <i class="fas fa-chart-bar mr-2"></i>Stats
                </a>
            </div>
        </div>
    </nav>

    <main class="container mx-auto px-4 py-8">
        <div class="mb-8">
            <h2 class="text-3xl font-bold text-gray-800">Hashtag Streams</h2>
            <p class="text-gray-600 mt-2">Monitor and manage Fediverse hashtag streams.</p>
        </div>

        <div class="bg-white rounded-lg shadow-md p-6 mb-8">
            <h3 class="text-xl font-bold text-gray-800 mb-6">
                <i class="fas fa-plus-circle mr-2 text-green-500"></i>Add New Stream
            </h3>
            <form id="addStreamForm" class="space-y-4">
                <div>
                    <label class="block text-gray-700 mb-2" for="hashtag">Hashtag</label>
                    <input type="text" id="hashtag" name="hashtag"
                           class="w-full px-4 py-2 border border-gray-300 rounded-lg"
                           placeholder="#example" required>
                    <p class="text-gray-500 text-sm mt-1">Enter without the # symbol</p></div>
                </div>
                <div>
                    <label class="block text-gray-700 mb-2" for="instance">Instance</label>
                    <input type="text" id="instance" name="instance"
                           class="w-full px-4 py-2 border border-gray-300 rounded-lg"
                           placeholder="mastodon.social" value="{{ default_instance }}" required>
                </div>
                <div class="flex items-center">
                    <input type="checkbox" id="active</div>" name="active" class="mr-2" checked>
                    <label for="active" class="text-gray-700">Active</label>
                </div>
                <button type="submit"
                        class="w-full bg-green-500 text-white py-3 rounded-lg font-semibold hover:bg-green-600">
                    <i class="fas fa-plus mr-2"></i>Add Stream
                </button>
            </form>
        </div>

        <div class="bg-white rounded-lg shadow-md p-6">
            <div class="flex justify-between items-center mb-6">
                <h3 class="text-xl font-bold text-gray-800">
                    <i class="fas fa-list mr-2 text-blue-500"></i>Streams
                </h3>
                <span class="bg-blue-100 text-blue-800 text-sm font-semibold px-3 py-1 rounded-full">
                    {{ streams|length }} streams
                </span>
            </div>

            {% if streams %}
            <div class="space-y-4">
                {% for stream in streams %}
                <div class="border border-gray-200 rounded-lg p-4">
                    <div class="flex justify-between items-start">
                        <div>
                            <div class="flex items-center">
                                <h4 class="text-lg font-semibold text-gray-800">
                                    <i class="fas fa-hashtag mr-2 text-indigo-500"></i>#{{ stream.hashtag }}
                                </h4>
                                {% if stream.active %}
                                <span class="ml-3 bg-green-</div>100 text-green-800 text-xs font-semibold px-2 py-1 rounded">
                                    <i class="fas fa-play mr-1"></i>Active
                                </span>
                                {% else %}
                                <span class="ml-3 bg-gray-100 text-gray-800 text-xs font-semibold px-2 py-1 rounded">
                                    <i class="fas fa-pause mr-1"></i>Paused
                                </span>
                                {% endif %}
                            </div>
                            <p class="text-gray-600 mt-1">
                                <i class="fas fa-server mr-1"></i>{{ stream.instance }}
                            </p>
                            <p class="text-gray-500 text-sm mt-2">
                                <i class="far fa-clock mr-1"></i>Created {{ stream.created_at }}
                            </p>
                        </div>
                    </div>
                </div>
                {% endfor %}
            </div>
            {% else %}
            <div class="text-center py-12">
                <i class="fas fa-hashtag text-4xl text-gray-300 mb-4"></i>
                <p class="text-gray-500">No streams configured yet.</p>
            </div>
            {% endif %}
        </div>
    </main>

    <footer class="bg-gray-800 text-white mt-12">
        <div class="container mx-auto px-4 py-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <div class="flex items-center mb-4">
                        <div class="rounded-full p-2 bg-white/10 mr-4">
                            <i class="fas fa-water"></i>
                        </div>
                        <div>
                            <h2 class="text-xl font-bold">{{ app_name }}</h2>
                            <p class="text-gray-300">Fediverse Content Stream Filtering</p>
                        </div>
                    </</div>div>
                    <p class="text-gray-400">Inspired by the ancient Dujiangyan irrigation system</p>
                </div>
                <div class="text-center md:text-right">
                    <p class="text-gray-400">Version {{ app_version }}</p>
                    <p class="text-gray-400">分流 - Divide the Flow</p>
                </div>
            </div>
        </div>
    </footer>

    <script>
        function toggleMobileMenu() {
            const menu = document.getElementById('mobileMenu');
            menu.classList.toggle('hidden');
        }

        document.getElementById('addStreamForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            const hashtag = document.getElementById('hashtag').value.trim();
            const instance = document.getElementById('instance').value.trim();
            const active =</script> document.getElementById('active').checked;

            try {
                const response = await fetch('/api/streams/', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        hashtag: hashtag.replace('#', ''),
                        instance: instance,
                        active: active
                    })
                });

                if (response.ok) {
                    alert('Stream added successfully!');
                    window.location.reload();
                } else {
                    const error = await response.json();
                    alert('Error: ' + error.detail);
                }
            } catch (error) {
                alert('Network error: ' + error.message);
            }
        });
    </script>
</body>
</html>
