<!-- templates/students/import.html - Simplified Version -->
{% extends 'base.html' %}
{% load static %}

{% block title %}Import Students - Rapha-Bethel BNPS{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0 text-gray-800">Import Students</h1>
        <a href="{% url 'students:student_list' %}" class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left"></i> Back to Student List
        </a>
    </div>

    <div class="row">
        <div class="col-md-8 mx-auto">
            <!-- CSV Upload Card -->
            <div class="card shadow mb-4">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0"><i class="fas fa-upload"></i> Upload Student CSV File</h5>
                </div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data" action="{% url 'students:import_students_csv' %}">
                        {% csrf_token %}
                        
                        <div class="mb-4">
                            <label class="form-label">Select CSV File</label>
                            <input type="file" name="file" class="form-control" accept=".csv" required>
                            <small class="text-muted">
                                File must be in CSV format with headers matching your data
                            </small>
                        </div>
                        
                        <div class="mb-4">
                            <label class="form-label fw-bold">
                                Target Class
                                <span class="text-muted fw-normal ms-1">(optional override)</span>
                            </label>
                            <select name="class_id" class="form-control">
                                <option value="">-- Use Class column from CSV --</option>
                                {% for class in classes %}
                                <option value="{{ class.id }}">{{ class.name }}</option>
                                {% endfor %}
                            </select>
                            <small class="text-muted">
                                Select a class here to assign <strong>all students</strong> in the file to that class,
                                overriding the Class column in the CSV.
                            </small>
                        </div>

                        <div class="alert alert-warning py-2 mb-4" style="font-size:.85rem">
                            <i class="fas fa-exclamation-triangle me-1"></i>
                            <strong>Class is required.</strong> Every row must have a valid Class code
                            (e.g. <code>CL6-A</code>, <code>CM2-A</code>, <code>NUR1-A</code>),
                            or select a Target Class above. Rows without a class will be skipped and reported as errors.
                        </div>
                        
                        <div class="mb-4">
                            <h6>CSV Format Options:</h6>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="card-header bg-light">
                                            <h6 class="mb-0">Format 1: Class 6 Style</h6>
                                        </div>
                                        <div class="card-body">
                                            <pre class="small mb-0">
NAME,DATE OF BIRTH,PLACE OF BIRTH,SEX
John Doe,15/05/2015,Douala,M
Jane Smith,22/08/2015,Yaounde,F</pre>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="card-header bg-light">
                                            <h6 class="mb-0">Format 2: Standard</h6>
                                        </div>
                                        <div class="card-body">
                                            <pre class="small mb-0">
First Name,Last Name,Date of Birth,Gender,Class,Parent Name,Parent Phone
John,Doe,15/05/2015,M,CL5-A,Peter Doe,677889900
Jane,Smith,22/08/2015,F,CL5-A,Mary Smith,699123456</pre>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="d-grid gap-2">
                            <a href="{% url 'students:download_student_sample' %}" class="btn btn-success mb-2">
                                <i class="fas fa-download"></i> Download Sample CSV Template
                            </a>
                            <a href="{% url 'students:download_class6_sample' %}" class="btn btn-info mb-2">
                                <i class="fas fa-download"></i> Download Class 6 Sample
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-upload"></i> Import Students
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Simple Import Option -->
            <div class="card shadow">
                <div class="card-header bg-success text-white">
                    <h5 class="mb-0"><i class="fas fa-info-circle"></i> Import Instructions</h5>
                </div>
                <div class="card-body">
                    <ol class="mb-0">
                        <li>Download the sample CSV template</li>
                        <li>Fill in your student data following the format</li>
                        <li>Upload the file using the form above</li>
                        <li>The system will automatically generate student IDs</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    pre {
        font-size: 0.8rem;
        background: #f8f9fa;
        padding: 10px;
        border-radius: 5px;
    }
</style>
{% endblock %}