<?php 
   
   include "databaseConnect.php";  

   $hotel_name = $hotel_link = $rating_comment = $review_number = $pricing =  $free_cancellation = $no_pre_payment =  $hotel_address =  $image_url = $amenities = $hotelId = '';
   if(isset($_GET['hotelId']) && !empty($_GET['hotelId'])){
        $hotelId = $_GET['hotelId'];
        $query = "SELECT * FROM tblhoteldetails where hotel_id =".$_GET['hotelId']; 
        $result = mysqli_query($conn, $query);
        if(mysqli_num_rows($result) >0){
            $rows = mysqli_fetch_assoc($result);
            $hotel_name = $rows['hotel_name'];
            $page_heading = $rows['page_heading'];
            $hotel_link = $rows['hotel_link'];
            $rating_comment = $rows['rating_comment'];
            $review_number = $rows['review_number'];
            $pricing = $rows['pricing'];
            $free_cancellation = $rows['free_cancellation'];
            $no_pre_payment = $rows['no_pre_payment'];
            $hotel_address = $rows['hotel_address'];
            $image_url = $rows['image_url'];
            $locationURL = $rows['hotel_location'];
            $slug = $rows['slug'];
            $amenities = $rows['amenities'];
            $page_backgroung_Image = $rows['page_backgroung_Image'];
        }
   }else{
    header('location: admin.php?msg=error');
   }

   include "header.php";
?>
<style>
    .switch {
        position: relative;
        display: inline-block;
        width: 50px;
        height: 23px;
    }
    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }
    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        transition: .4s;
    }
    .slider:before {
        position: absolute;
        content: "";
        height: 15px;
        width: 15px;
        left: 4px;
        bottom: 4px;
        background-color: white;
        transition: .4s;
    }
    input:checked + .slider {
        background-color: #0d6efd;
    }
    input:focus + .slider {
        box-shadow: 0 0 1px #0d6efd;
    }
    input:checked + .slider:before {
        transform: translateX(26px);
    }
    .slider.round {
        border-radius: 34px;
    }
    .slider.round:before {
        border-radius: 50%;
    }
</style>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0"><i class="nav-icon fas fa-tachometer-alt"></i> Dashboard</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item">Home</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content" style = "min-height:454px;">
        <div class="container-fluid">
            <form method="post" id="editForm" action = "manage-hotels-process.php" enctype="multipart/form-data">
                <input type = "hidden" name="type" value="editForm" />
                <input type = "hidden" name="hotelID" value="<?=$hotelId?>" />
                <div class="row">
                    <div class="col-sm-6">
                        <label for="examplegoogleMapSlug">Page Slug</label>
                        <input type="text" class="form-control" id="examplegoogleMapSlug" name="editslug" placeholder="Enter Slug" value="<?=$slug?>">
                    </div>
                    <div class="col-sm-6">
                        <label for="examplegooglePageHeading">Page Heading</label>
                        <input type="text" class="form-control" id="examplegooglePageHeading" name="editPageHeading" placeholder="Enter Page Heading" value="<?=$page_heading?>" >
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputHotelName">Hotel Name</label>
                            <input type="text" class="form-control" id="exampleInputHotelName" name="edithotelName" placeholder="Enter Hotel Name" value="<?=$hotel_name?>">
                            <small class="text-danger error" id="errorHotelName"></small>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputLink">Link</label>
                            <input type="text" class="form-control" id="exampleInputLink" name="edithotelLink" placeholder="Enter Link" value="<?=$hotel_link?>">
                            <small class="text-danger error" id="errorLink"></small>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputRatingComment">Rating Comment</label>
                            <input type="text" class="form-control" id="exampleInputRatingComment" name="editRatingComment" placeholder="Enter Rating Comment" value="<?= $rating_comment?>">
                            <small class="text-danger error" id="errorRatingComment"></small>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputReviewNumber">Review Number</label>
                            <input type="text" class="form-control" id="exampleInputReviewNumber" name="editReviewNumber" placeholder="Enter Review Number" value="<?=$review_number?>">
                            <small class="text-danger error" id="errorReviewNumber"></small>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputPricing">Pricing (in $s) </label>
                            <input type="text" class="form-control" id="exampleInputPricing" name="editPricing" placeholder="Enter Pricing (in $s)" value="<?=$pricing?>">
                            <small class="text-danger error" id="errorPricing"></small>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <small class="text-muted">Choose Only One Option from below</small>
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputFreeCancellation">Free Cancellations</label><br>
                            <label class="switch">
                                <input type="checkbox" id="exampleInputFreeCancellation" name="editFreeCancellation" class="toggle-topCity-btn" <?= $free_cancellation == 1 ?'checked':''?> ><span class="slider round"></span>
                            </label>
                        </div>
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputFreeCancellation">Best Price Guarantee</label><br>
                            <label class="switch">
                                <input type="checkbox" value="2" id="exampleInputFreeCancellation-2" name="editFreeCancellation" class="toggle-topCity-btn" <?= $free_cancellation == 2 ?'checked':''?>><span class="slider round"></span>
                            </label>
                        </div>
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputFreeCancellation">Great location</label><br>
                            <label class="switch">
                                <input type="checkbox" value="3" id="exampleInputFreeCancellation-3" name="editFreeCancellation" class="toggle-topCity-btn" <?= $free_cancellation == 3 ?'checked':''?>><span class="slider round"></span>
                            </label>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <small class="text-muted">Choose Only One Option from below</small>
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputNoPre-payment">No Pre-payment</label><br>
                            <label class="switch">
                                <input type="checkbox" id="exampleInputNoPre-payment" name="editNoPre-payment" class="toggle-topCity-btn" <?=$no_pre_payment == 1 ?'checked':''?>><span class="slider round"></span>
                            </label>
                        </div>
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputNoPre-payment">Recently booked</label><br>
                            <label class="switch">
                                <input type="checkbox" value="2" id="exampleInputNoPre-payment-2" name="editNoPre-payment" class="toggle-topCity-btn" <?=$no_pre_payment == 2 ?'checked':''?> ><span class="slider round"></span>
                            </label>
                        </div>
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputNoPre-payment">Highly rated for cleanliness</label><br>
                            <label class="switch">
                                <input type="checkbox" value="3" id="exampleInputNoPre-payment-3" name="editNoPre-payment" class="toggle-topCity-btn" <?=$no_pre_payment == 3 ?'checked':''?> ><span class="slider round"></span>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputHoteleditress">Hotel editress</label>
                            <input type="text" class="form-control" id="exampleInputHoteleditress" name="editHoteleditress" placeholder="Enter Hotel editress" value="<?=$hotel_address?>">
                            <small class="text-danger error" id="errorHoteleditress"></small>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group" bis_skin_checked="1">
                            <label for="exampleInputImageURL">Hotel Image Url</label>
                            <input type="text" class="form-control" id="exampleInputImageURL" name="editImageURL" placeholder="Enter Hotel Iamge URL" value="<?=$image_url?>">
                            <small class="text-danger error" id="errorImageURL"></small>
                        </div>
                    </div>
                </div>
                <div class="row mb-3">
                    <div class="col-sm-6">
                        <label for="examplegoogleMapURl">Hotel Location Url</label>
                        <input type="text" class="form-control" id="examplegoogleMapURl" name="editgoogleMapURL" placeholder="Enter Hotel Location Link" value="<?=$locationURL?>">
                    </div>  
                    <div class="col-sm-6">
                        <label for="image">Page Heading Image</label>
                        <input type="file" class="form-control" name="editImageFile" id="editImageFile" accept="image/*">
                        <small class="text-muted">Leave empty if no changes required</small>
                        <input type ="hidden" name="editImageURL_older" value="<?=$page_backgroung_Image?>" />
                    </div>                  
                </div>
                <div class="row mb-3">
                    <div class="col-sm-12">
                        <label>Amenities</label>
                        <textarea class="form-control" rows="3" name="hotelAmenities" placeholder="Enter Amenities..."><?=$amenities?></textarea>
                        <small class="text-danger error" id="errorAmenities"></small>
                    </div>
                </div>
                <div class="row text-right mb-3" style="justify-content:right;">
                    <button type="submit" class="btn btn-primary btn-lg" id="editHotelData" >Submit</button>
                </div>
            </form>
        </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
</div>
<?php include "footer.php"?>
<script>
    $(document).ready(function() {
        $('#editHotelData').closest('form').on('submit', function(event) {
            let isValid = true;
            $('.error').text('');
            const fields = [
                { id: "#exampleInputHotelName", errorId: "#errorHotelName", message: "Hotel name is required" },
                { id: "#exampleInputLink", errorId: "#errorLink", message: "Link is required" },
                { id: "#exampleInputRatingComment", errorId: "#errorRatingComment", message: "Rating comment is required" },
                { id: "#exampleInputReviewNumber", errorId: "#errorReviewNumber", message: "Review number is required" },
                { id: "#exampleInputPricing", errorId: "#errorPricing", message: "Pricing is required" },
                { id: "#exampleInputHoteleditress", errorId: "#errorHoteleditress", message: "Hotel address is required" },
                { id: "#exampleInputImageURL", errorId: "#errorImageURL", message: "Hotel image URL is required" },
                { id: "[name='hotelAmenities']", errorId: "#errorAmenities", message: "Amenities are required" }
            ];
            fields.forEach(field => {
                if ($(field.id).val().trim() === "") {
                    $(field.errorId).text(field.message);
                    isValid = false;
                }
            });
            if (!isValid) {
                event.preventDefault();
            }
        });
    });

    $(document).ready(function() {
        $('#exampleInputPricing').on('keydown', function(e) {
            if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 37, 38, 39, 40]) !== -1 || 
                (e.keyCode >= 48 && e.keyCode <= 57) || 
                (e.keyCode >= 96 && e.keyCode <= 105)) {
                return true;
            }
            e.preventDefault();
            return false;
        });

        $('#exampleInputReviewNumber').on('keydown', function(e) {
            if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 37, 38, 39, 40]) !== -1 || 
                (e.keyCode >= 48 && e.keyCode <= 57) || 
                (e.keyCode >= 96 && e.keyCode <= 105)) {
                return true;
            }
            e.preventDefault();
            return false;
        });
    });


</script>