package templates

templ Analytics(user User) {
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Reading Analytics - Bookhoard</title>
        <script src="/static/htmx.min.js"></script>
        <script src="/static/toast.js"></script>
        <link href="/static/style.css" rel="stylesheet">
        <script src="/static/theme.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    </head>
    <body class="theme-{ user.Theme }">
        @Header(user, "/analytics")

        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
            <div class="mb-8">
                <h1 class="text-3xl font-bold mb-2" style="color: var(--text-primary)">📊 Reading Analytics</h1>
                <p style="color: var(--text-secondary)">Track your reading habits and device usage</p>
            </div>

            <!-- Date Range Picker -->
            <div class="card p-4 rounded-lg border mb-6" style="background-color: var(--bg-secondary); border-color: var(--border);">
                <div class="flex flex-wrap gap-4 items-center">
                    <div class="flex-1 min-w-[200px]">
                        <label class="block text-sm font-medium mb-2" style="color: var(--text-secondary);">Start Date</label>
                        <input type="date" id="start-date" onchange="loadAnalytics()"
                            class="w-full px-4 py-2 border rounded-lg"
                            style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border);">
                    </div>
                    <div class="flex-1 min-w-[200px]">
                        <label class="block text-sm font-medium mb-2" style="color: var(--text-secondary);">End Date</label>
                        <input type="date" id="end-date" onchange="loadAnalytics()"
                            class="w-full px-4 py-2 border rounded-lg"
                            style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border);">
                    </div>
                    <div class="flex items-end">
                        <button onclick="loadAnalytics()" class="btn-primary px-6 py-2 rounded-lg">Update</button>
                    </div>
                </div>
            </div>

            <!-- Stats Cards -->
            <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8" id="stats-container">
                <div class="card p-6 rounded-lg border transition-all duration-200 ease hover:-translate-y-0.5 hover:shadow-lg" style="background-color: var(--bg-secondary); border-color: var(--border);">
                    <h3 class="text-lg font-semibold mb-2" style="color: var(--text-secondary);">Books Read</h3>
                    <p id="total-books" class="text-3xl font-bold" style="color: var(--text-primary);">-</p>
                </div>
                <div class="card p-6 rounded-lg border transition-all duration-200 ease hover:-translate-y-0.5 hover:shadow-lg" style="background-color: var(--bg-secondary); border-color: var(--border);">
                    <h3 class="text-lg font-semibold mb-2" style="color: var(--text-secondary);">Pages Read</h3>
                    <p id="total-pages" class="text-3xl font-bold" style="color: var(--text-primary);">-</p>
                </div>
                <div class="card p-6 rounded-lg border transition-all duration-200 ease hover:-translate-y-0.5 hover:shadow-lg" style="background-color: var(--bg-secondary); border-color: var(--border);">
                    <h3 class="text-lg font-semibold mb-2" style="color: var(--text-secondary);">Reading Time</h3>
                    <p id="reading-time" class="text-3xl font-bold" style="color: var(--text-primary);">-</p>
                </div>
                <div class="card p-6 rounded-lg border transition-all duration-200 ease hover:-translate-y-0.5 hover:shadow-lg" style="background-color: var(--bg-secondary); border-color: var(--border);">
                    <h3 class="text-lg font-semibold mb-2" style="color: var(--text-secondary);">Completion Rate</h3>
                    <p id="completion-rate" class="text-3xl font-bold" style="color: var(--text-primary);">-</p>
                </div>
            </div>

            <!-- Charts Row -->
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
                <!-- Daily Reading Chart -->
                <div class="card p-6 rounded-lg border" style="background-color: var(--bg-secondary); border-color: var(--border);">
                    <h3 class="text-lg font-semibold mb-4" style="color: var(--text-primary);">Daily Reading Minutes</h3>
                    <div class="h-80">
                        <canvas id="daily-reading-chart"></canvas>
                    </div>
                </div>

                <!-- Device Usage Chart -->
                <div class="card p-6 rounded-lg border" style="background-color: var(--bg-secondary); border-color: var(--border);">
                    <h3 class="text-lg font-semibold mb-4" style="color: var(--text-primary);">Device Usage</h3>
                    <div class="h-80">
                        <canvas id="device-usage-chart"></canvas>
                    </div>
                </div>
            </div>

            <!-- Popular Books -->
            <div class="card p-6 rounded-lg border" style="background-color: var(--bg-secondary); border-color: var(--border);">
                <h3 class="text-lg font-semibold mb-4" style="color: var(--text-primary);">Most Read Books</h3>
                <div id="popular-books" class="space-y-3">
                    <div class="text-center py-8" style="color: var(--text-secondary);">
                        <div class="loading-spinner mx-auto mb-4"></div>
                        <p>Loading analytics...</p>
                    </div>
                </div>
            </div>
        </div>

        <script src="/static/analytics.js"></script>
    </body>
    </html>
}
