{% extends "base.html" %}

{% block content %}
<div class="container py-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h2>Research Studies</h2>
        <a class="btn btn-primary" href="{% url 'research:study_create' %}">+ Create Study</a>
    </div>
    <p class="text-muted">Create and manage research study packets that randomise participants to Atlas case collections.</p>

    {% if studies %}
    <table class="table table-dark table-striped table-hover table-sm">
        <thead>
            <tr>
                <th>Name</th>
                <th>ID</th>
                <th>Status</th>
                <th>Randomisation</th>
                <th>Participants</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for study in studies %}
            <tr>
                <td>{{ study.name }}</td>
                <td><code>{{ study.pk }}</code></td>
                <td>
                    {% if study.active %}
                        <span class="badge bg-success">Active</span>
                    {% else %}
                        <span class="badge bg-secondary">Inactive</span>
                    {% endif %}
                </td>
                <td>{{ study.get_randomisation_mode_display }}</td>
                <td>{{ study.participants.count }}</td>
                <td>
                    <a class="btn btn-sm btn-outline-primary" href="{% url 'research:study_detail' study.pk %}">Open</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% else %}
    <div class="alert alert-info">No studies have been created yet.</div>
    {% endif %}
</div>
{% endblock %}
