{% extends 'base.html' %}
{% load static %}
{% load crispy_forms_tags %}

{% block title %}Курсы | Автошкола{% endblock %}

{% block content %}
<div class="container">
    <div class="row mb-4">
        <div class="col">
            <h2 class="text-center mb-4">Курсы</h2>
        </div>
    </div>

    {% if user.is_authenticated and user.instructor %}
        <div class="row mb-4">
            <div class="col">
                <a href="{% url 'course:create' %}" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>Добавить курс
                </a>
            </div>
        </div>
    {% endif %}

    <div class="row">
        {% if courses %}
            {% for course in courses %}
                <div class="col-md-4 mb-4">
                    <div class="card h-100 shadow">
                        <div class="card-body">
                            <h5 class="card-title">{{ course.title }}</h5>
                            <p class="card-text">{{ course.description|truncatewords:30 }}</p>
                        </div>
                        <div class="card-footer bg-transparent">
                            {% if user.is_authenticated %}
                            <a href="{% url 'course:detail' course.pk %}" class="btn btn-primary">
                                <i class="fas fa-info-circle me-2"></i>Подробнее
                            </a>
                            {% endif %}
                            {% if user.is_authenticated and user.instructor %}
                                <a href="{% url 'course:update' course.pk %}" class="btn btn-warning">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <a href="{% url 'course:delete' course.pk %}" class="btn btn-danger">
                                    <i class="fas fa-trash"></i>
                                </a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <div class="col">
                <div class="alert alert-info">
                    <i class="fas fa-info-circle me-2"></i>На данный момент нет доступных курсов.
                </div>
            </div>
        {% endif %}
    </div>
</div>
{% endblock %} 