{% extends 'base.html' %}

{% block content %}

<div class="container mt-4">

    {% if current_user.is_authenticated %}

        <h3 class="mb-4">Hello, {{ current_user.user_name }}!</h3>

        {% if current_user.auto_app.masini %}

            <div class="row g-4">

                {% for id_car, masina in current_user.auto_app.masini.items() %}
                <div class="col-md-6 col-lg-4">

                    <!-- Car Card -->
                    <div class="card shadow-sm h-100">

                        <div class="card-body">
                            <h5 class="card-title">
                                <a href="/summary/{{ id_car }}/{{ masina }}" class="text-decoration-none">
                                    {{ masina }}
                                </a>
                            </h5>

                            <hr>

                            <!-- Export Without Files -->
                            <form action="/summary/{{ id_car }}/{{ masina }}" method="POST">
                                <button type="submit" name="export_detail_table_as_sql"
                                        class="btn btn-outline-primary btn-sm w-100 mb-2">
                                    Export Without Files
                                </button>
                            </form>

                            <!-- Export With Files -->
                            <form action="/summary/{{ id_car }}/{{ masina }}" method="POST">
                                <button type="submit" name="export_detail_table_with_files"
                                        class="btn btn-outline-primary btn-sm w-100 mb-2">
                                    Export With Files
                                </button>
                            </form>

                            <!-- Delete Car -->
                            <form action="/delete_masina/{{ id_car }}/{{ masina }}" method="POST"
                                  onsubmit="return confirm('Are you sure you want to delete {{ masina }}?');">
                                <button type="submit" name="delete_all_inputs_from_user_for_car"
                                        class="btn btn-outline-danger btn-sm w-100">
                                    Delete Car
                                </button>
                            </form>
                        </div>
                    </div>

                </div>
                {% endfor %}
            </div>

            <div class="text-center mt-5">
                <a href="/add_masina" class="btn btn-success btn-lg">
                    + Add / Import a New Car
                </a>
            </div>

        {% else %}

            <div class="alert alert-info mt-4">
                You don't have any cars yet.
            </div>

            <a href="/add_masina" class="btn btn-success">
                + Add / Import a Car
            </a>

        {% endif %}

    {% else %}
        <div class="alert alert-warning mt-4">
            Please log in to continue.
        </div>
    {% endif %}

</div>

{% endblock %}
