{% extends "core/base.html" %}
{% block title %}CSV Import{% endblock %}

{% block content %}
<div class="container py-4">
    <h2 class="mb-4">📤 Import Plant Data</h2>

    {# Display flash messages (error, success, etc.) #}
    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for category, message in messages %}
                <div
                    class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show"
                    role="alert"
                >
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}
    {% endwith %}

    <form method="POST" enctype="multipart/form-data">
        {# Hidden CSRF token #}
        <input type="hidden" name="csrf_token" value="{{ csrf_token }}">

        <div class="mb-3">
            <label for="file" class="form-label">Choose CSV File</label>
            <input
                type="file"
                class="form-control"
                id="file"
                name="file"
                accept=".csv,.zip"
                required
            >
            <div class="form-text">
                Required columns: <code>uuid</code>, <code>plant_type</code>, <code>name</code><br>
                Optional columns: <code>scientific_name</code>, <code>mother_uuid</code>
            </div>
        </div>

        <button type="submit" class="btn btn-success">Upload</button>
    </form>
</div>
{% endblock %}
