<?php
require_once('template/head.php');
?>
    <div class="container-fluid section">
        <h2>Gestions des réservations de "<?=htmlspecialchars($hotel->getName())?>"</h2>
        
            <form class="row g-3 needs-validation justify-content-end" style="padding-top: 30px;">
                <div class="col-md-4">
                    <div class="form-outline">
                        <input
                                type="text"
                                class="form-control"
                                id="validationCustom01"
                                value="Mark"
                                required
                        />
                        <label for="validationCustom01" class="form-label">VIP</label>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-outline">
                        <input
                                type="text"
                                class="form-control"
                                id="validationCustom02"
                                value="Otto"
                                required
                        />
                        <label for="validationCustom02" class="form-label">Last name</label>
                        <div class="valid-feedback">Looks good!</div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="input-group form-outline">
                        <span class="input-group-text" id="inputGroupPrepend">@</span>
                        <input
                                type="text"
                                class="form-control"
                                id="validationCustomUsername"
                                aria-describedby="inputGroupPrepend"
                                required
                        />
                        <label for="validationCustomUsername" class="form-label">Username</label>
                        <div class="invalid-feedback">Please choose a username.</div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-outline">
                        <input type="text" class="form-control" id="validationCustom03" required />
                        <label for="validationCustom03" class="form-label">City</label>
                        <div class="invalid-feedback">Please provide a valid city.</div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-outline">
                        <input type="text" class="form-control" id="validationCustom05" required />
                        <label for="validationCustom05" class="form-label">Zip</label>
                        <div class="invalid-feedback">Please provide a valid zip.</div>
                    </div>
                </div>
                <div class="col-1">
                    <button class="btn btn-success" type="submit">Ajouter</button>
                </div>
            </form>
            <hr class="my-5">


        <table class="table table-hover">
            <thead>
            <tr>
                <th scope="col">Email VIP</th>
                <th scope="col">Nombre d'occupants</th>
                <th scope="col">Date d'arrivée</th>
                <th scope="col">Date de sortie</th>
                <th scope="col">Action</th>
            </tr>
            </thead>
            <tbody>
            <?php
                forEach($reservations as $reservation){
                    ?>
                    <tr>
                        <th scope="row"><?=$reservation->getUserEmail()?></th>
                        <td><?=$reservation->getPeopleCount()?></td>
                        <td><?=$reservation->getStartDate()?></td>
                        <td><?=$reservation->getEndDate()?></td>
                        <td><button onclick="deleteReservation('<?=$reservation->getUserEmail()?>')" class="btn btn-danger">Supprimer</button></td>
                    </tr>
                        <?php
                }
            ?>
            </tbody>
        </table>
    </div>
<script>
    function deleteReservation(email){
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "<?=genURL('manager/') . $hotel->getId() . '/delete'?>", true);
        xhr.send('email=' + email);
    }
</script>
<?php
require_once('template/footer.php');
?>