{% extends 'generic/base.html' %}

{% block content %}
<div class="container py-4">
    <div class="row justify-content-center">
        <div class="col-12 col-xl-10">
            <div class="card shadow">
                <div class="card-header bg-warning text-dark d-flex justify-content-between align-items-center">
                    <h3 class="card-title mb-0">Preview Import Exam Answers</h3>
                    <span class="badge bg-dark text-white fs-6">{{ answers_count }} Answers in file</span>
                </div>
                <div class="card-body">
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <strong>Exam:</strong> <span class="text-primary">{{ eid_str }}</span>
                        </div>
                        <div class="col-md-6">
                            <strong>Candidate/User ID:</strong> <span class="text-primary">{{ cid_str }}</span>
                        </div>
                    </div>
                    
                    <p class="text-muted">
                        Review the changes below before confirming the import. Existing database answers will be overwritten.
                    </p>
                    
                    <div class="table-responsive" style="max-height: 400px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px;">
                        <table class="table table-striped table-hover mb-0">
                            <thead class="table-dark sticky-top">
                                <tr>
                                    <th>Question ID</th>
                                    <th>Part (qidn)</th>
                                    <th>File Answer (To Import)</th>
                                    <th>Database Answer (To Overwrite)</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for item in preview_items %}
                                <tr>
                                    <td>{{ item.qid }}</td>
                                    <td>{{ item.qidn }}</td>
                                    <td><code class="text-success">{{ item.posted }}</code></td>
                                    <td>
                                        {% if item.existing %}
                                            <code class="text-danger">{{ item.existing }}</code>
                                        {% else %}
                                            <span class="text-muted italic">- None -</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if item.action == "Update" %}
                                            <span class="badge bg-warning text-dark">Overwrite (Update)</span>
                                        {% else %}
                                            <span class="badge bg-success">New (Create)</span>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    
                    <form method="post" class="mt-4">
                        {% csrf_token %}
                        <input type="hidden" name="confirm" value="1">
                        <div class="d-flex justify-content-between align-items-center">
                            <a href="{% url 'generic:import_exam_answers' %}" class="btn btn-secondary">Cancel</a>
                            <button type="submit" class="btn btn-success px-4 fw-bold">Confirm Import</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
