<!doctype html>
<html lang="{{ current_locale() }}" class="h-100">
    {% set current_theme = current_theme() %}

    <head>
        {{ current_theme.headertags() }}
        <title>{{ page_title }} - NOW LMS</title>
        {{ current_theme.local_style() }}
        <style>
            .course-card {
                border: none;
                border-radius: 15px;
                box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
                transition: transform 0.2s ease, box-shadow 0.2s ease;
                margin-bottom: 1.5rem;
            }
            .course-card:hover {
                transform: translateY(-5px);
                box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
            }
            .header-section {
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                color: white;
                border-radius: 10px;
                margin-bottom: 2rem;
            }
            {% if user_type == "instructor" %}
            .header-section {
                background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
            }
            {% endif %}
            .course-badge {
                background: rgba(255, 255, 255, 0.2);
                border: 1px solid rgba(255, 255, 255, 0.3);
            }
        </style>
    </head>

    <body>
        {{ current_theme.navbar() }}

        <main>
            {{ current_theme.notify() }}

            <div class="container px-0 py-3">
                <!-- Header Section -->
                <div class="header-section p-4 mb-4">
                    <div class="row align-items-center">
                        <div class="col-md-8">
                            <h2 class="mb-1">
                                {% if user_type == "student" %}
                                <i class="bi bi-journal-bookmark me-2"></i>{{ _('Mis Cursos de Aprendizaje') }}
                                {% else %}
                                <i class="bi bi-book-half me-2"></i>{{ _('Mis Cursos de Enseñanza') }}
                                {% endif %}
                            </h2>
                            <p class="mb-0 opacity-75">
                                {% if user_type == "student" %}
                                {{ _('Continúa tu viaje de aprendizaje donde lo dejaste') }}
                                {% else %}
                                {{ _('Gestiona y administra tus cursos creados') }}
                                {% endif %}
                            </p>
                        </div>
                        <div class="col-md-4 text-end">
                            {% if user_type == "student" %}
                            <a href="{{ url_for('course.lista_cursos') }}" class="btn btn-light" style="border-radius: 25px">
                                <i class="bi bi-search me-1"></i>{{ _('Explorar Más Cursos') }}
                            </a>
                            {% else %}
                            <a href="{{ url_for('course.nuevo_curso') }}" class="btn btn-light" style="border-radius: 25px">
                                <i class="bi bi-plus-circle me-1"></i>{{ _('Crear Nuevo Curso') }}
                            </a>
                            {% endif %}
                        </div>
                    </div>
                </div>

                <!-- Courses Section -->
                {% if courses %}
                <div class="row">
                    {% for curso in courses %}
                    <div class="col-lg-6 col-xl-4">
                        <div class="card course-card">
                            <div class="card-body">
                                <!-- Course Header -->
                                <div class="d-flex justify-content-between align-items-start mb-3">
                                    <h5 class="card-title mb-0">{{ curso.nombre }}</h5>
                                    <span class="badge course-badge">{{ curso.codigo }}</span>
                                </div>

                                <!-- Course Description -->
                                {% if curso.descripcion_corta %}
                                <p class="card-text text-muted mb-3">{{ curso.descripcion_corta[:100] }}{% if curso.descripcion_corta|length > 100 %}...{% endif %}</p>
                                {% endif %}

                                <!-- Course Info -->
                                <div class="row text-center mb-3">
                                    <div class="col-4">
                                        <small class="text-muted d-block">{{ _('Nivel') }}</small>
                                        <span class="badge bg-primary">{{ curso.nivel }}</span>
                                    </div>
                                    <div class="col-4">
                                        <small class="text-muted d-block">{{ _('Estado') }}</small>
                                        {% if curso.estado == "open" %}
                                        <span class="badge bg-success">{{ _('Abierto') }}</span>
                                        {% elif curso.estado == "draft" %}
                                        <span class="badge bg-secondary">{{ _('Borrador') }}</span>
                                        {% else %}
                                        <span class="badge bg-warning">{{ curso.estado }}</span>
                                        {% endif %}
                                    </div>
                                    <div class="col-4">
                                        <small class="text-muted d-block">{{ _('Acceso') }}</small>
                                        {% if curso.publico %}
                                        <span class="badge bg-info">{{ _('Público') }}</span>
                                        {% else %}
                                        <span class="badge bg-secondary">{{ _('Privado') }}</span>
                                        {% endif %}
                                    </div>
                                </div>

                                <!-- Action Buttons -->
                                <div class="d-grid gap-2">
                                    {% if user_type == "student" %}
                                    <a href="{{ url_for('course.tomar_curso', course_code=curso.codigo) }}" 
                                       class="btn btn-primary">
                                        <i class="bi bi-play-circle me-2"></i>{{ _('Continuar Aprendiendo') }}
                                    </a>
                                    <a href="{{ url_for('course.curso', course_code=curso.codigo) }}" 
                                       class="btn btn-outline-secondary btn-sm">
                                        <i class="bi bi-eye me-2"></i>{{ _('Vista Previa') }}
                                    </a>
                                    {% else %}
                                    <a href="{{ url_for('course.administrar_curso', course_code=curso.codigo) }}" 
                                       class="btn btn-success">
                                        <i class="bi bi-gear me-2"></i>{{ _('Administrar Curso') }}
                                    </a>
                                    <div class="btn-group w-100" role="group">
                                        <a href="{{ url_for('course.curso', course_code=curso.codigo) }}" 
                                           class="btn btn-outline-primary btn-sm">
                                            <i class="bi bi-eye me-1"></i>{{ _('Vista Previa') }}
                                        </a>
                                        <a href="{{ url_for('course.editar_curso', course_code=curso.codigo) }}" 
                                           class="btn btn-outline-secondary btn-sm">
                                            <i class="bi bi-pencil me-1"></i>{{ _('Editar') }}
                                        </a>
                                    </div>
                                    {% endif %}
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <!-- Empty State -->
                <div class="text-center py-5">
                    <div class="mb-4">
                        {% if user_type == "student" %}
                        <i class="bi bi-journal-bookmark display-1 text-muted opacity-25"></i>
                        {% else %}
                        <i class="bi bi-book-half display-1 text-muted opacity-25"></i>
                        {% endif %}
                    </div>
                    <h3 class="text-muted mb-3">
                        {% if user_type == "student" %}
                        {{ _('No tienes cursos inscritos') }}
                        {% else %}
                        {{ _('No tienes cursos creados') }}
                        {% endif %}
                    </h3>
                    <p class="text-muted mb-4">
                        {% if user_type == "student" %}
                        {{ _('¡Explora nuestro catálogo y comienza tu viaje de aprendizaje!') }}
                        {% else %}
                        {{ _('¡Crea tu primer curso y comienza a enseñar!') }}
                        {% endif %}
                    </p>
                    {% if user_type == "student" %}
                    <a href="{{ url_for('course.lista_cursos') }}" class="btn btn-primary btn-lg">
                        <i class="bi bi-search me-2"></i>{{ _('Explorar Cursos') }}
                    </a>
                    {% else %}
                    <a href="{{ url_for('course.nuevo_curso') }}" class="btn btn-success btn-lg">
                        <i class="bi bi-plus-circle me-2"></i>{{ _('Crear Mi Primer Curso') }}
                    </a>
                    {% endif %}
                </div>
                {% endif %}

                <!-- Back to Dashboard -->
                <div class="text-center mt-4">
                    <a href="{{ url_for('home.panel') }}" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-left me-2"></i>{{ _('Regresar al Panel') }}
                    </a>
                </div>
            </div>
        </main>
    </body>
</html>