{% include 'header.twig' %}

<div class="wrapper-content">
    <br>
    <div class="wrapper-content__header">
        <h1 style="text-align: center;">Welcome to {{ site["site_name"] }}</h1>
    </div>
    <div class="wrapper-content__body">
        <div class="container">
            <div class="row align-items-stretch justify-content-center">
                <!-- Username Card -->
                <div class="col-lg-3 col-md-6 col-sm-12 mt-2">
                    <div class="card h-100" style="padding: 15px;">
                        <h2 style="font-size: 22px; text-align: center;">{{ user["username"] }}</h2>
                        <p style="text-align: center;">Username</p>
                    </div>
                </div>

                <!-- Total Spent Card -->
                <div class="col-lg-3 col-md-6 col-sm-12 mt-2">
                    <div class="card h-100" style="padding: 15px;">
                        <h2 style="font-size: 22px; text-align: center;">{{ user["spent"] }}</h2>
                        <p style="text-align: center;">Total Spent</p>
                    </div>
                </div>

                <!-- Total Orders Card -->
                <div class="col-lg-3 col-md-6 col-sm-12 mt-2">
                    <div class="card h-100" style="padding: 15px;">
                        <h2 style="font-size: 22px; text-align: center;">{{ totalorders }}</h2>
                        <p style="text-align: center;">Total Orders</p>
                    </div>
                </div>

                <!-- Total Balance Card -->
                <div class="col-lg-3 col-md-6 col-sm-12 mt-2">
                    <div class="card h-100" style="padding: 15px;">
                        <h2 style="font-size: 22px; text-align: center;">{{ user["balance"] }}</h2>
                        <p style="text-align: center;">Total Balance</p>
                    </div>
                </div>

                <!-- Total Tickets Card -->
                <div class="col-lg-3 col-md-6 col-sm-12 mt-2">
                    <div class="card h-100" style="padding: 15px;">
                        <h2 style="font-size: 22px; text-align: center;">{{ user["tickets"] }}</h2>
                        <p style="text-align: center;">Total Tickets</p>
                    </div>
                </div>
            </div>

            <!-- Recent Orders Section -->
            <div class="mt-4">
                <h3>Recent Orders</h3>
                <table class="table table-dark table-striped">
                    <thead>
                        <tr>
                            <th>Order ID</th>
                            <th>Service</th>
                            <th>Amount</th>
                            <th>Status</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for order in recent_orders %}
                        <tr>
                            <td>{{ order["id"] }}</td>
                            <td>{{ order["service"] }}</td>
                            <td>{{ order["amount"] }}</td>
                            <td>{{ order["status"] }}</td>
                            <td>{{ order["date"] }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

            <!-- Analytics Charts Section -->
            <div class="mt-4">
                <h3>Analytics</h3>
                <div class="row">
                    <div class="col-lg-6 col-md-12">
                        <div class="card h-100" style="padding: 15px;">
                            <h4>Orders Over Time</h4>
                            <canvas id="ordersChart"></canvas>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-12">
                        <div class="card h-100" style="padding: 15px;">
                            <h4>Spending Analytics</h4>
                            <canvas id="spendingChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // Example Chart.js setup (replace with dynamic data as needed)
    const ordersChart = new Chart(document.getElementById('ordersChart'), {
        type: 'line',
        data: {
            labels: {{ analytics["order_dates"] | json_encode }},
            datasets: [{
                label: 'Orders',
                data: {{ analytics["order_counts"] | json_encode }},
                borderColor: 'blue',
                fill: false
            }]
        }
    });

    const spendingChart = new Chart(document.getElementById('spendingChart'), {
        type: 'bar',
        data: {
            labels: {{ analytics["spending_categories"] | json_encode }},
            datasets: [{
                label: 'Spending',
                data: {{ analytics["spending_values"] | json_encode }},
                backgroundColor: 'green'
            }]
        }
    });
</script>

{% include 'footer.twig' %}
