{% extends "www/cohorts/base.html" %}
{% block title %}
    _("Manage") {{ course.title  }}
{% endblock %}

{% block page_content %}
    {% if cohorts %}
        <h2>
            {{ _("Cohorts") }}
        </h2>
        <div class="row">
            {% for cohort in cohorts %}
            <div class="col-md-6">
            {{ render_cohort(course, cohort) }}
            </div>
            {% endfor %}
        </div>
    {% else %}
        <h2>
            {{ _("Permission Denied") }}
        </h2>
        <p>
            {{ _("You don't have permission to manage this course.") }}
        </p>
    {% endif %}
{% endblock %}

{% macro render_cohort(course, cohort) %}
<div class="cards-parent">
    <div class="common-card-style flex-column p-5">
        <h5 class="card-title">
            {{ cohort.title }}
        </h5>

        {% if cohort.begin_date %}
        <h6 class="card-subtitle mb-2 text-muted">
            {{ frappe.utils.format_date(cohort.begin_date, "medium") }} - {{ frappe.utils.format_date(cohort.end_date, "medium") }}
        </h6>
        {% endif %}

        <p class="mb-0">
            {{ frappe.db.count("Cohort Subgroup", {"cohort": cohort.name}) }} {{ _("Subgroups") }}
            | {{ frappe.db.count("Cohort Mentor", {"cohort": cohort.name}) }} {{ _("Mentors") }}
            | {{ frappe.db.count("LMS Batch Membership", {"cohort": cohort.name}) }} {{ _("Students") }}
            | {{ frappe.db.count("Cohort Join Request", {"cohort": cohort.name}) }} {{ _("Join Requests") }}
        </p>


        <a class="stretched-link" href="/courses/{{course.name}}/cohorts/{{cohort.slug}}"></a>
    </div>
</div>

{% endmacro %}
