<?php
include "classes/class.loader.php";
$html = new html();
$html->bacground_emoji();
$DashboardWidget = new DashboardWidget();
$calls = new functions();
$db = new db();
?>
<style>
    body {
        background-color: #bebebee7;
        color: white;
    }
</style>
<div class="header">
    <input type="text" id="username" name="username" value="<?php echo $_SESSION['username']; ?>" readonly />
    <button onclick="window.location.href='login.php'">LOG OUT</button>
    <button onclick="window.location.href='payments.php'">PAYMENTS</button>
    <button onclick="window.location.href='bookings.php'">BOOKINGS</button>
    <button onclick="window.location.href='news.php'">NEWS</button>
    <button onclick="window.location.href='help.php'">HELP</button>
    <button onclick="window.location.href='services.php'">SERVICES</button>
</div>

<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(); ?></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'],
            'booking.php?record_id=' . $booking['record_id']
        ];

    }


    echo DashboardWidget::tableBlock(
        'Latest Bookings',
        ['No', 'User', 'Date', 'Time', 'Type'],
        $table_data,
        '90vw'
    );
    ?>
</div>