<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Upload CSV File</title>
    {% include 'favicon.html' %}
    <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
</head>
<body>
    {% include 'header.html' %}
    <main class="container mt-5 pt-3">
        <h1>Upload CSV File</h1>

    <!-- Display flash messages (only errors) -->
    {% with messages = get_flashed_messages(category_filter=["error"]) %}
        {% if messages %}
            <details>
                <summary>Errors found during submission (click to expand):</summary>
                <ul>
                    {% for message in messages %}
                        <li>{{ message }}</li>
                    {% endfor %}
                </ul>
            </details>
        {% endif %}
    {% endwith %}

    <!-- Upload form -->
    <form method="POST" enctype="multipart/form-data"
        {% if mode == "import" %}
            action="/import_from_csv"
        {% elif mode == "edit" %}
            action="/edit_using_csv"
        {% endif %}
    >
        <label for="file">Choose a CSV file:</label>
        <input type="file" id="file" name="file" accept=".csv" required>
        <br><br>
        <button type="submit">Upload</button>
        <button type="button" onclick="window.location.href='/'">Cancel</button>
    </form>
    </main>
    <!-- Bootstrap JS (for dropdowns) -->
    <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
</body>
</html>