<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>"What's the Damage" - {{ _('Result') }}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous" defer></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('downloadCSVButton').addEventListener('click', function() {
                fetch('/download', { method: 'GET', credentials: 'same-origin' })
                    .then(response => response.blob())
                    .then(blob => {
                        const url = window.URL.createObjectURL(blob);
                        const a = document.createElement('a');
                        a.style.display = 'none';
                        a.href = url;
                        a.download = 'result.csv';
                        document.body.appendChild(a);
                        a.click();
                        window.URL.revokeObjectURL(url);
                    })
                    .catch(error => console.error('Error downloading CSV:', error));
            });
        });
    </script>
</head>
<body>
    <header>
        {% include 'header.html' %}
    </header>
    <main class="container">
        <h1 class="text-center p-2 pb-1">{{ _('Processed results') }}</h1>
        <div class="row">
            <div class="col-md-12 mb-3">
                <div class="table-responsive">
                    {{ table|safe }}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <a href="/" class="btn btn-secondary mt-3 mb-3">{{ _('Back') }}</a>
            </div>
            <div class="col-md-6 text-end">
                <button type="button" class="btn btn-secondary mt-3 mb-3" id="downloadCSVButton">{{ _('Download CSV') }}</button>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12 text-end">
                <p class="fw-light fs-6">{{ _('Note: Should you want to have better results in importing the generated CSV file, please make sure to check "No Currenty Format" on the previous form.') }}</p>
            </div>
        </div>
    </main>
    <footer class="bg-success text-white text-center py-3 mt-3">
        {% include 'footer.html' %}
    </footer>
</body>
</html>