{% extends 'base.html' %}

{% block title %}{{ project_name }}{% endblock %}

{% block content %}
<div class="container mt-5">
    <div class="row mb-4">
        <div class="col-md-6">
            <h1>Welcome to {{ project_name }}</h1>
            <p>Your personal space to reflect and grow.</p>
        </div>
        <div class="col-md-6 text-md-end">
            {% if user.is_authenticated %}
                <a href="{% url 'core:create_mood_entry' %}" class="btn btn-primary">+ Log New Mood</a>
            {% else %}
                <a href="{% url 'admin:login' %}" class="btn btn-primary">Log In</a>
            {% endif %}
        </div>
    </div>

    {% if user.is_authenticated %}
        <h2>Your Recent Moods</h2>
        {% if mood_entries %}
            <div class="list-group">
                {% for entry in mood_entries %}
                    <div class="list-group-item list-group-item-action flex-column align-items-start">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1">Mood Score: {{ entry.mood_score }}/5</h5>
                            <small>{{ entry.date_time|date:"Y-m-d H:i" }}</small>
                        </div>
                        <p class="mb-1">{{ entry.note|truncatewords:30 }}</p>
                        {% if entry.activities.all %}
                        <small>Activities: 
                            {% for activity in entry.activities.all %}
                                <span class="badge bg-secondary">{{ activity.name }}</span>
                            {% endfor %}
                        </small>
                        {% endif %}
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <p>You haven't logged any moods yet. <a href="{% url 'core:create_mood_entry' %}">Get started!</a></p>
        {% endif %}
    {% else %}
        <div class="p-5 mb-4 bg-light rounded-3">
            <div class="container-fluid py-5">
                <h1 class="display-5 fw-bold">Track Your Mental Wellness</h1>
                <p class="col-md-8 fs-4">Gain insights into your moods and activities to better understand your mental health. Log in to begin your journey.</p>
                <a href="{% url 'admin:login' %}" class="btn btn-primary btn-lg">Log In & Get Started</a>
            </div>
        </div>
    {% endif %}
</div>
{% endblock %}
