{% extends 'base.html' %}

{% block content %}
<div class="container mt-5">
    <div class="row">
        <div class="col-md-8">
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h2 class="card-title mb-0">Program Details</h2>
                    <a href="{% url 'program_pdf' pk=program.pk %}" class="btn btn-secondary">Download PDF</a>
                </div>
                <div class="card-body">
                    <p><strong>Patient:</strong> {{ program.patient_name }}</p>
                    <p><strong>Patient Email:</strong> {{ program.patient_email }}</p>
                    <p><strong>Clinician:</strong> {{ program.clinician_name }}</p>
                    <p><strong>Created:</strong> {{ program.created_at|date:"d M Y" }}</p>
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Exercises</h3>
                </div>
                <div class="card-body">
                    <div class="row">
                        {% for exercise in program.exercises.all %}
                        <div class="col-md-6 col-lg-4 mb-4">
                            <div class="card h-100">
                                {% if exercise.get_video_thumbnail %}
                                <a href="{{ exercise.video_url }}" target="_blank">
                                    <img src="{{ exercise.get_video_thumbnail }}" class="card-img-top" alt="{{ exercise.title }}">
                                </a>
                                {% endif %}
                                <div class="card-body">
                                    <h5 class="card-title">{{ exercise.title }}</h5>
                                    <p class="card-text">{{ exercise.description }}</p>
                                </div>
                            </div>
                        </div>
                        {% empty %}
                        <p>No exercises have been added to this program yet.</p>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Add New Exercise</h3>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        {{ exercise_form.as_p }}
                        <button type="submit" class="btn btn-primary w-100">Add Exercise</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
