{% extends "base.html" %}
{% from "_macros.html" import render_flash_messages %}

{% block content %}
    <h1 class="mb-4">Welcome to CPM Assessment</h1>
    <p class="lead">Explore the assessments available below. You can start a free assessment directly, or if you have been referred by a consultant, please use your unique link.</p>

    <h2 class="mt-5">Available Assessments</h2>
    {% if assessments %}
        <div class="row">
            {% for assessment in assessments %}
                <div class="col-md-4 mb-4">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">{{ assessment.name }}</h5>
                            <h6 class="card-subtitle mb-2 text-muted">Type: {{ assessment.assessment_type }} {% if assessment.is_free %}(Free){% endif %}</h6>
                            <p class="card-text">{{ assessment.description }}</p>
                            {% if current_user.is_authenticated %}
                                {% if assessment.is_free %}
                                    <a href="{{ url_for('main.start_user_assessment', assessment_id=assessment.id) }}" class="btn btn-primary">Start Assessment</a>
                                {% else %}
                                    <button class="btn btn-secondary" disabled>Login to Start (Paid)</button>
                                {% endif %}
                            {% else %}
                                <a href="{{ url_for('auth.login') }}" class="btn btn-primary">Login to Start</a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% else %}
        <p>No assessments are currently available. Please check back later.</p>
    {% endif %}
{% endblock %}
