<?php
include "classes/class.loader.php";
$html = new html();
$html->bacground_emoji();
$DashboardWidget = new DashboardWidget();
$calls = new functions();
$db = new db();
$html->header();
?>
<style>
    body {
        background-color: #bebebee7;
        color: white;
    }
</style>

<div class="home_container">
    <div class="container_square">
        <h2>BOOKINGS FOR THE MONTH</h2>
        <div class="line"></div>
        <h1><?php echo $calls->get_total_bookings_this_month(); ?></h1>
        <br>
    </div>
    <div class="container_square">
        <h2>TOTAL MADE THIS MONTH</h2>
        <div class="line"></div>
        <h1><?php echo "R " . $calls->get_total_value_from_payments_this_month(); ?>
        </h1>
        <br>
    </div>
    <div class="container_square">
        <h2>BOOKINGS FOR LAST MONTH</h2>
        <div class="line"></div>
        <h1><?php echo $calls->get_total_bookings_last_month(); ?></h1>
        <br>
    </div>
    <div class="container_square">
        <h2>LAST MONTH PAYMENTS</h2>
        <div class="line"></div>
        <h3><?php echo "R " . $calls->get_total_value_from_payments_last_month(); ?></h3>
    </div>
    <?php
    echo DashboardWidget::includeAssets();


    $table_data = [];

    $bookings_res = $db->query("SELECT * FROM `bookings` WHERE `status` = 1 ORDER BY record_id DESC LIMIT 15");
    while ($booking = $bookings_res->fetch_assoc()) {

        $table_data[] = [
            $booking['record_id'],
            $calls->get_username($booking['user_id']),
            $booking['date_of_booking'],
            $booking['time_start'],
            $booking['type'],
            $calls->get_service_name($booking['service']),
            'booking.php?record_id=' . $booking['record_id']
        ];

    }

    if (count($table_data) != 0) {


        echo DashboardWidget::tableBlock(
            'WAITING APPROVAL',
            ['No', 'User', 'Date', 'Time', 'Type', 'Service'],
            $table_data,
            '90vw'
        );
    }
    ?>
</div>
<br>
<?php $html->html_end(); ?>