<?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='home.php'">HOME</button>
    <button onclick="window.location.href='payments.php'">PAYMENTS</button>
    <button onclick="window.location.href='bookings.php'" style='border: 2px solid whit'>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">
    <?php
    echo DashboardWidget::includeAssets();

    $table_data = [];

    $bookings_res = $db->query("SELECT * FROM `bookings` WHERE 1 ORDER BY record_id DESC LIMIT 15");
    while ($booking = $bookings_res->fetch_assoc()) {
        if ($booking['status'] == 0) {
            $status = 'Pending Payment';
        } else if ($booking['status'] == 1) {
            $status = 'Pending Approval';
        } else if ($booking['status'] == 2) {
            $status = 'APPROVED';
        } else if ($booking['status'] == 3) {
            $status = 'DECLINED';
        }

        $table_data[] = [
            $booking['record_id'],
            $calls->get_username($booking['user_id']),
            $booking['date_of_booking'],
            $booking['time_start'],
            $status,
            $booking['type'],
            'booking.php?record_id=' . $booking['record_id']
        ];

    }


    echo DashboardWidget::tableBlock(
        'Latest Bookings',
        ['No', 'User', 'Date', 'Time', 'status', 'Type'],
        $table_data,
        '90vw'
    );
    ?>
</div>