package templates

templ Admin(user User) {
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Admin Dashboard - Bookhoard</title>
        <script src="/static/htmx.min.js"></script>
        <script src="/static/toast.js"></script>
        <link href="/static/style.css" rel="stylesheet">
    </head>
    <body class="theme-tokyo-night">
        <nav class="border-b" style="border-color: var(--border); background-color: var(--bg-secondary)">
            <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
                <div class="flex justify-between items-center h-16">
                    <div class="flex items-center">
                        <h1 class="text-xl font-bold" style="color: var(--text-primary)">📚 Bookhoard</h1>
                    </div>
                    <div class="flex items-center space-x-4">
                        <a href="/" class="px-3 py-2 text-sm hover:opacity-80" style="color: var(--text-secondary)">Library</a>
                        <span style="color: var(--text-secondary)">Welcome, { user.Username }!</span>
                        <button onclick="logout()" class="btn-primary px-4 py-2 rounded text-sm">
                            Logout
                        </button>
                    </div>
                </div>
            </div>
        </nav>

        <div class="flex min-h-screen" style="background-color: var(--bg-primary)">
            <aside class="w-64 border-r" style="background-color: var(--bg-secondary); border-color: var(--border)">
                <div class="p-6">
                    <h2 class="text-lg font-semibold mb-6" style="color: var(--text-primary)">Admin Panel</h2>
                    <nav class="space-y-2">
                        <a href="/admin" class="block px-4 py-2 rounded-lg bg-accent text-bg-primary" style="color: var(--text-primary)">
                            🏠 Dashboard
                        </a>
                        <a href="/admin/profile" class="block px-4 py-2 rounded-lg hover:opacity-80" style="color: var(--text-primary)">
                            👤 Profile Settings
                        </a>
                        <a href="/admin/library" class="block px-4 py-2 rounded-lg hover:opacity-80" style="color: var(--text-primary)">
                            📚 Library Management
                        </a>
                    </nav>
                </div>
            </aside>

            <main class="flex-1 p-8">
                <div class="max-w-4xl">
                    <div class="mb-8">
                        <h1 class="text-3xl font-bold mb-2" style="color: var(--text-primary)">Dashboard</h1>
                        <p style="color: var(--text-secondary)">Overview of your Bookhoard library and settings</p>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                        <div class="card p-6 rounded-lg border" style="background-color: var(--bg-secondary); border-color: var(--border)">
                            <div class="flex items-center space-x-3">
                                <div class="text-3xl">📖</div>
                                <div>
                                    <h3 class="font-semibold" style="color: var(--text-primary)">Library</h3>
                                    <p style="color: var(--text-secondary)" class="text-sm">Manage your ebook collection</p>
                                </div>
                            </div>
                            <a href="/" class="mt-4 inline-block text-sm btn-secondary px-3 py-1 rounded">View Library</a>
                        </div>

                        <div class="card p-6 rounded-lg border" style="background-color: var(--bg-secondary); border-color: var(--border)">
                            <div class="flex items-center space-x-3">
                                <div class="text-3xl">⚙️</div>
                                <div>
                                    <h3 class="font-semibold" style="color: var(--text-primary)">Settings</h3>
                                    <p style="color: var(--text-secondary)" class="text-sm">Configure your preferences</p>
                                </div>
                            </div>
                            <a href="/admin/profile" class="mt-4 inline-block text-sm btn-secondary px-3 py-1 rounded">Manage Settings</a>
                        </div>


                    </div>

                    <div class="card p-6 rounded-lg border" style="background-color: var(--bg-secondary); border-color: var(--border)">
                        <h3 class="text-xl font-semibold mb-4" style="color: var(--text-primary)">Quick Actions</h3>
                        <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                            <button onclick="quickScan()" class="btn-primary p-4 rounded-lg text-left">
                                <div class="font-medium">Scan Library</div>
                                <div style="color: var(--text-secondary)" class="text-sm">Find new ebooks in your folders</div>
                            </button>
                            <a href="/admin/library" class="btn-secondary p-4 rounded-lg text-left block">
                                <div class="font-medium">Manage Folders</div>
                                <div style="color: var(--text-secondary)" class="text-sm">Add or remove scan directories</div>
                            </a>
                        </div>
                    </div>
                </div>
            </main>
        </div>

        <script>
            function quickScan() {
                fetch('/api/scanner/scan', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('token')
                    },
                    body: JSON.stringify({
                        folder_paths: []
                    })
                }).then(res => res.json()).then(data => {
                    alert(data.message || 'Scan completed successfully!');
                }).catch(err => {
                    console.error('Scan error:', err);
                    alert('Scan failed. Please check your folder configuration.');
                });
            }

            function logout() {
                localStorage.removeItem('token');
                localStorage.removeItem('user');
                window.location.href = '/';
            }

            document.addEventListener('DOMContentLoaded', function() {
                loadTheme();
            });
        </script>
    </body>
    </html>
}