{% extends "base.html" %}

{% block content %}
    <h1>All Completed Assessment Reports</h1>

    <form method="POST" action="{{ url_for('admin.reports') }}" class="mb-4">
        <div class="input-group">
            <input type="text" name="search_query" class="form-control" placeholder="Search by Center Case ID or Consultant Reg. No." value="{{ search_query or '' }}">
            <div class="input-group-append">
                <button type="submit" class="btn btn-primary">Search</button>
            </div>
        </div>
    </form>

    <h2>Assessment Assignments</h2>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Assessment Name</th>
                <th>Taken By</th>
                <th>Completion Date</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for assignment in assignments %}
            <tr>
                <td>{{ assignment.assessment.name }}</td>
                <td>
                    {% if assignment.client %}
                        {{ assignment.client.name }} ({{ assignment.client.email }})
                        <br>
                        <small>Case ID: {{ assignment.client.center_case_id or 'N/A' }}</small>
                    {% elif assignment.user %}
                        {{ assignment.user.username }} ({{ assignment.user.email }})
                        <br>
                        <small>Consultant Reg No: {{ assignment.user.registration_number or 'N/A' }}</small>
                    {% else %}
                        N/A
                    {% endif %}
                </td>
                <td>{{ assignment.completed_date.strftime('%Y-%m-%d %H:%M') if assignment.completed_date else 'N/A' }}</td>
                <td>
                    <a href="{{ url_for('main.view_report', assignment_id=assignment.id) }}" class="btn btn-sm btn-info">View Report</a>
                </td>
            </tr>
            {% else %}
            <tr>
                <td colspan="4" class="text-center">No completed assignments found.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}
