<!-- upload_form.html -->
{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h3 class="mb-0">Upload Goods Declaration PDF</h3>
                </div>
                <div class="card-body">
                    {% if messages %}
                    <div class="mb-3">
                        {% for message in messages %}
                        <div class="alert alert-{{ message.tags }}">
                            {{ message }}
                        </div>
                        {% endfor %}
                    </div>
                    {% endif %}
                    
                    <form method="post" enctype="multipart/form-data" id="uploadForm">
                        {% csrf_token %}
                        
                        <div class="mb-3">
                            <label for="pdf_file" class="form-label">
                                <i class="bi bi-file-earmark-pdf"></i> Select PDF File
                            </label>
                            <input type="file" class="form-control" name="pdf_file" id="pdf_file" 
                                   accept=".pdf" required>
                            <div class="form-text">Only PDF files are accepted</div>
                        </div>
                        
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary" id="submitBtn">
                                <i class="bi bi-upload"></i> Upload and Process
                            </button>
                        </div>

                        {% if form.errors %}
                        <div class="alert alert-danger">
                            <h5>Date Format Errors:</h5>
                            <ul>
                                {% for field, errors in form.errors.items %}
                                    {% if 'date' in field %}
                                        {% for error in errors %}
                                            <li>{{ field|title }}: {{ error }}</li>
                                        {% endfor %}
                                    {% endif %}
                                {% endfor %}
                            </ul>
                        </div>
                        {% endif %}

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
document.getElementById('uploadForm').addEventListener('submit', function() {
    // Show loading state
    const submitBtn = document.getElementById('submitBtn');
    submitBtn.disabled = true;
    submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Processing...';
});
</script>
{% endblock %}