{% extends 'base.html' %}

{% block head %}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
{% endblock %}

{% block content %}
<div class="container">
    <h1>Mood Dashboard</h1>
    <canvas id="moodChart" width="400" height="200"></canvas>
</div>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        var ctx = document.getElementById('moodChart').getContext('2d');
        var chartData = JSON.parse('{{ chart_data|safe }}');
        
        var dates = chartData.map(function(d) { return d.date_time; });
        var scores = chartData.map(function(d) { return d.mood_score; });

        var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: dates,
                datasets: [{
                    label: 'Mood Score',
                    data: scores,
                    borderColor: 'rgba(75, 192, 192, 1)',
                    borderWidth: 1,
                    fill: false
                }]
            },
            options: {
                scales: {
                    x: {
                        type: 'time',
                        time: {
                            unit: 'day'
                        }
                    },
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });
    });
</script>
{% endblock %}
