{% extends 'base.html' %}
{% block title %}Import Jobs - RepairsHub{% endblock %}
{% block content %}
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <nav aria-label="breadcrumb" class="mb-4">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{% url 'job_list' %}" class="text-decoration-none">Jobs</a></li>
                    <li class="breadcrumb-item active">Import</li>
                </ol>
            </nav>

            <div class="card border-0 shadow-lg overflow-hidden">
                <div class="bg-primary p-4 text-white">
                    <h2 class="h4 mb-1">Import Jobs</h2>
                    <p class="mb-0 opacity-75">Upload an Excel or CSV file to bulk create jobs.</p>
                </div>
                <div class="card-body p-5">
                    {% if messages %}
                    {% for message in messages %}
                    <div class="alert alert-{{ message.tags }} alert-dismissible fade show mb-4" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                    </div>
                    {% endfor %}
                    {% endif %}

                    <div class="mb-5">
                        <h6 class="text-uppercase text-muted smaller fw-bold mb-3">Instructions</h6>
                        <ul class="small text-muted mb-0">
                            <li>Supported formats: <strong>.xlsx, .xls, .csv</strong></li>
                            <li>The following columns are recognized:
                                <ul class="mt-2">
                                    <li><code>Job Ref</code> (Required, Unique)</li>
                                    <li><code>UPRN</code> (Optional)</li>
                                    <li><code>Address 1</code> (Required)</li>
                                    <li><code>Postcode</code> (Required)</li>
                                    <li><code>Status</code> (Optional, defaults to starting status)</li>
                                </ul>
                            </li>
                            <li>Duplicate <code>Job Ref</code> will update existing jobs.</li>
                        </ul>
                    </div>

                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        <div class="mb-4">
                            <label class="form-label fw-bold">{{ form.file.label }}</label>
                            {{ form.file }}
                            {% if form.file.errors %}
                            <div class="text-danger small mt-1">{{ form.file.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary btn-lg rounded-pill">
                                <i class="bi bi-cloud-upload me-2"></i> Process Import
                            </button>
                            <a href="{% url 'job_list' %}" class="btn btn-link text-muted">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>

            <div class="mt-4 text-center">
                <p class="text-muted small">Need a template? <a href="{% url 'job_export' %}" class="text-decoration-none">Export existing jobs</a> to see the required format.</p>
            </div>
        </div>
    </div>
</div>
{% endblock %}
