<?php 
if( ! defined( 'ABSPATH' ) ) exit;
if(!is_admin()) {
global $wpdb, $post;
session_start();

?>

<div class="sync_form_wrapper_set sync_user_option">
	<div class="head_label">
		<h2>Hotel Accommodation</h2>
	</div>
	<div class="select_opt">
		<input type="button" value="Book a Room" name="book_room" class="book_room">
		<input type="button" value="Check Booking" name="check_booking" class="check_booking">  
	</div>
</div>


<div class="sync_form_wrapper sync_hotel_wrapper" style="display:none;">
	<div class="go_back">
		<span class="back_text"><i class="fa fa-arrow-left"></i>  Back</span>
	</div>
	<div class="sync_container pick-date">
		<div class="sync_options_currency">
		</div>
		<div class="sync_title">

			<h2><?php echo (($get_title[0]->option_value!='') ? esc_html($get_title[0]->option_value) : 'Room Reservation'); ?></h2>
			<?php
			if (!empty($_SESSION['message'])) {
			    echo '<p class="message"> '.esc_html($_SESSION['message']).'</p>';
			    unset($_SESSION['message']);
			}
			?>
		</div>
		<div class="sync_components">
			<form id="search_hotel_room" action="" method="post">
				<?php wp_nonce_field('search_hotel', 'search_hotel_nonce') ?>
				<div class="sync-holder-field">
					<div class="holder holder-calendar">
						<label>Check-in Date</label>
						<input required readonly id="datepicker_hotel" data-toggle="datepicker-hotel" value="<?php echo isset($_POST['date_arrive']) ? esc_attr($_POST['date_arrive']) : '' ?>" name="date_arrive">
					</div>
					<div style="display: none;" class="holder" data-toggle="datepicker"></div>
					<div class="holder holder-night quantity">
						<label>Duration</label>
						<input id="spend_night_hotel" type="number" min="1" max="30" step="1" maxlength="2" value="<?php echo isset($_POST['night_number']) ? esc_attr($_POST['night_number']) : '1' ?>" name="night_number"><span class="night night-text">night(s)</span>
					</div>
					<div class="holder holder-check-out no-border">
						<label>Check-out Date</label>
						<label class="date_departure"><?php echo isset($_POST['date_departure']) ? esc_html($_POST['date_departure']) : '' ?></label>
						<label id="date_departure_num"><?php echo isset($_POST['night_number']) ? '<i class="fa fa-moon-o fa-1x"></i> '.esc_html($_POST['night_number']).' night only' : '' ?></label>
						<input type="hidden" value="<?php echo isset($_POST['date_departure']) ? esc_attr($_POST['date_departure']) : '' ?>" name="date_departure" id="date_departure">
					</div>
					<div class="holder holder-guest-number quantity">
						<label>Guest(s)</label>
						<input type="number" class="number_of_guest" step="1" min="1" max="30" name="number_guest" maxlength="2">
					</div>
					<div class="holder holder-rooms-number quantity">
						<label>Room(s)</label>
						<input type="number" class="number_of_room" value="<?php echo isset($_POST['number_room']) ? esc_attr($_POST['number_room']) : '1' ?>" step="1" min="1" max="30" name="number_room" maxlength="2">
					</div>
					<div class="holder holder-bed-number quantity">
						<label>Bed(s)</label>
						<input type="number" class="number_of_bed" step="1" min="1" max="30" name="number_bed" maxlength="2">
						<!-- <input type="number" class="number_of_bed" step="1" min="1" max="30" name="number_bed" maxlength="2"> -->
					</div>
				</div>
				<div class="holder holder-check-availability">
					<div class="holder holder-check-room">
						<input type="button" value="Check Room" name="check_room" class="find-room" id="find-room">
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<?php    


	if( (!empty(sanitize_text_field($_GET['sync_options_currency_name']))) || (!empty(sanitize_text_field($_POST['date_arrive'])) && !empty(sanitize_text_field($_POST['night_number'])) && !empty(sanitize_text_field($_POST['number_guest'])) && !empty(sanitize_text_field($_POST['number_room'])))) {

		if (isset($_POST['search_hotel_nonce']) && wp_verify_nonce($_POST['search_hotel_nonce'], 'search_hotel')) {
			$_SESSION['sync_default_curreny'] = sanitize_text_field($_GET['sync_options_currency_name']);
			$date_arrive    = sanitize_text_field($_POST['date_arrive']);
			$date_departure = sanitize_text_field($_POST['date_departure']);
			$night_number   = intval($_POST['night_number']);
			$number_guest   = intval($_POST['number_guest']);
			$number_room    = intval($_POST['number_room']);
			$number_bed     = intval($_POST['number_bed']);
			
			$_SESSION['sync_date_arrive'] = $date_arrive;
			$_SESSION['sync_number_guest'] = $number_guest;
			$_SESSION['sync_number_room'] = $number_room;
			$_SESSION['sync_number_bed'] = $number_bed;
		
			include('personal-info.php');
			include('payment.php');
		}
	} else {
		
	}
} ?>

<script>
	jQuery(".select_opt .book_room").click( function () {
		jQuery(".sync_form_wrapper.sync_hotel_wrapper").show();
		jQuery(".sync_form_wrapper_set.sync_user_option").hide();
	});
	
	jQuery(".select_opt .check_booking").click( function () {
		jQuery(".sync_form_wrapper_set.sync_check_booking").show();
		jQuery(".sync_form_wrapper_set.sync_user_option").hide();
	});

	
	jQuery(".sync_hotel_wrapper .go_back").click( function () {
		jQuery('.sync_form_wrapper_set.sync_user_option').show();
		jQuery('.sync_form_wrapper.sync_hotel_wrapper').hide();
	});
	
	jQuery(".sync_check_booking .go_back").click( function () {
		jQuery('.sync_form_wrapper_set.sync_user_option').show();
		jQuery('.sync_form_wrapper_set.sync_check_booking').hide();
	});

	jQuery("#booking_info .close").click( function () {
		jQuery('body').loading('stop');
	});

	jQuery("#show_cancel .close").click( function () {
		jQuery('body').loading('stop');
		jQuery("#booking_info").show();
	});

	jQuery("#cancel_success .close").click( function () {
		jQuery('body').loading('stop');
	});

	jQuery("#cancel_success .close").click( function () {
		jQuery('body').loading('stop');
		location.reload();
	});

	jQuery("#cancel_success .close_modal").click( function () {
		jQuery('body').loading('stop');
		location.reload();
	});
</script>

