<?php
/**
 * The template for displaying search room item loop.
 *
 * This template can be overridden by copying it to yourtheme/wp-hotel-booking/search/loop.php.
 *
 * @author  ThimPress, leehld
 * @package WP-Hotel-Booking/Templates
 * @version 1.6
 */

/**
 * Prevent loading this file directly
 */
defined( 'ABSPATH' ) || exit();

global $hb_settings;

$gallery         = $room->gallery;
$featured        = $gallery ? array_shift( $gallery ) : false;
$single_purchase = get_option( 'tp_hotel_booking_single_purchase' );
$post_id = get_the_ID();
$room_size = get_post_meta($room->post->ID, 'framework-room-size', true);
$room_price = get_post_meta($room->post->ID, 'framework-room-price', true);
$room_sleeps = get_post_meta($room->post->ID, 'framework-room-sleeps', true);
$room_bed_size = get_post_meta($room->post->ID, 'framework-room-bed', true);
$room_bathroom = get_post_meta($room->post->ID, 'framework-room-bathroom', true);
$room_know_more = get_post_meta($room->post->ID, 'framework-room-know-more', true);
?>
 <div class="col-sm-6 col-md-6 col-lg-4 div-wapper">
<form name="hb-search-results"  class="hb-search-room-results <?php echo wp_kses_post($single_purchase ) ? 'single-purchase' : ''; ?>">
  <div class="">
    <div class="room-card">
      <div class="room-card-photo"> <?php echo get_the_post_thumbnail($room->post->ID, 'bestel-rooms-thumb', array('class' => 'img-fluid')); ?>
        <div class="flex-wrap-center"> 
          <?php do_action( 'hotel_booking_loop_before_item', $room->post->ID ); ?>
          <div class="hb-room-content">
            <div class="hb-room-info">
              <ul class="hb-room-meta">
                <li class="hb_search_add_to_cart">
                  <?php if (function_exists('bestel_get_option') && bestel_get_option('bestel-booking-option') ){ ?>
                      <a class="btn btn-primary room-qview" href="<?php echo esc_js('javascript:void(0)');?>" data-toggle="modal" data-target="#modalBooking"><?php echo esc_html__('BOOK NOW', 'bestel') ?></a>
                  <?php }else{ ?>
                      <button class="btn btn-primary room-qview searchroom"><?php echo esc_html__('BOOK NOW', 'bestel') ?></button>
                  <?php } ?>
                  
                </li>
              </ul>
            </div>
          </div>
          <?php wp_nonce_field( 'hb_booking_nonce_action', 'nonce' ); ?>
          <input type="hidden" name="check_in_date" value="<?php echo date( 'm/d/Y', hb_get_request( 'hb_check_in_date' ) ); ?>"/>
          <input type="hidden" name="check_out_date" value="<?php echo date( 'm/d/Y', hb_get_request( 'hb_check_out_date' ) ); ?>">
          <input type="hidden" name="room-id" value="<?php echo esc_attr( $room->post->ID ); ?>">
          <input type="hidden" name="hotel-booking" value="cart">
          <input type="hidden" name="action" value="hotel_booking_ajax_add_to_cart"/>
        </div>
      </div>
      <div class="room-card-info">
        <div class="row">
          <div class="col">
            <h3 class="room-type hb-room-name"><a href="<?php echo get_the_permalink( $room->ID ) ?>"><?php echo esc_attr( $room->name ) ?></a></h3>
          </div>
          <div class="col-auto ml-auto">
            <div class="room-card-attr"> <span data-toggle="popover" data-trigger="hover" data-placement="top" data-content="<?php echo esc_attr($room_sleeps, 'bestel') ?>"><i class="icon-two-man"></i></span> <span data-toggle="popover" data-trigger="hover" data-placement="top" data-content="<?php echo esc_attr($room_bed_size, 'bestel') ?>"><i class="icon-double-size-bed"></i></span> <span data-toggle="popover" data-trigger="hover" data-placement="top" data-content="<?php echo esc_attr($room_bathroom, 'bestel') ?>"><i class="icon-bathtub"></i></span> </div>
          </div>
        </div>
        <div class="room-size mt-0"><?php echo esc_html__('Room size:', 'bestel') ?> <?php echo esc_html($room_size,'bestel') ?> <?php echo esc_html__('m', 'bestel'); ?><sup><?php echo esc_html__('2', 'bestel'); ?></sup></div>

        <?php if (function_exists('bestel_get_option') && !bestel_get_option('bestel-booking-option') ){ ?>

        <div class="row">
          <div class="col">
            <?php if ( ! $single_purchase ) { ?>
              
                <div class="hb_search_quantity">
                  <label>
                    <?php esc_html_e( 'Quantity: ', 'bestel' ); ?>
                  </label>
                <div>
                <?php
                
    					hb_dropdown_numbers(
    						array(
    							'name'             => 'hb-num-of-rooms',
    							'min'              => 0,
    							'show_option_none' => '',
    							'max'              => $room->post->available_rooms,
    							'class'            => 'number_room_select'
    						)
    					);
    				?>
              </div>
            </div>
            <?php } else { ?>
            <select name="hb-num-of-rooms" class="number_room_select" style="display: none;">
              <option value="1">1</option>
            </select>
            <?php } ?>
          </div>
        </div>

        <?php } ?>

        <?php do_action( 'hotel_booking_loop_after_item', $room->post->ID ); ?>
        <div class="row">
          <div class="col">
            <div class="room-price"><?php echo hb_format_price( $room->amount_singular ) ?></div>
            <div class="hb_view_price"> <a href=""
                               class="hb-view-booking-room-details"><i class="icon-information"></i></a>
              <?php hb_get_template( 'search/booking-room-details.php', array( 'room' => $room ) ); ?>
            </div>
          </div>
          <div class="col-auto ml-auto"> <a href="<?php the_permalink(); ?>" class="room-information" data-toggle="popover" data-trigger="hover" data-placement="bottom"><i class="icon-information"></i><?php echo esc_html__('Know more', 'bestel') ?></a>
            <div class="popover-content d-none">
              <?php
				echo wp_kses($room_know_more, array(
							'ul' => array(''),
							'li' => array(''),
							'a' =>  array('href'),
						) );
			  ?>
            </div>
          </div>
        </div>
        <li class="hb-room clearfix">
          <?php if ( ( isset( $atts['gallery'] ) && $atts['gallery'] === 'true' ) || $hb_settings->get( 'enable_gallery_lightbox' ) ) { ?>
          <?php hb_get_template( 'loop/gallery-lightbox.php', array( 'room' => $room ) ) ?>
          <?php } ?>
        </li>
      </div>
    </div>
  </div>
</form>
<div id="hotel_booking_room_hidden"></div>
<!--Single search form--> 
<script type="text/html" id="tmpl-hb-room-load-form">

    <form action="POST" name="hb-search-single-room" class="hb-search-room-results hotel-booking-search hotel-booking-single-room-action">
		
        <div class="hb-booking-room-form-head">
            <h2><?php printf( '%s', $room->name ) ?></h2>
            <p class="description"><?php esc_html_e( 'Please set arrival date and departure date before check available.', 'bestel' ); ?></p>
        </div>

        <div class="hb-search-results-form-container">
            <div class="hb-booking-room-form-group">
                <div class="hb-booking-room-form-field hb-form-field-input">
                    <input type="text" name="check_in_date" value="{{ data.check_in_date }}" placeholder="<?php esc_html_e( 'Arrival Date', 'bestel' ); ?>" />
                </div>
            </div>
            <div class="hb-booking-room-form-group">
                <div class="hb-booking-room-form-field hb-form-field-input">
                    <input type="text" name="check_out_date" value="{{ data.check_out_date }}" placeholder="<?php esc_html_e( 'Departure Date', 'bestel' ); ?>" />
                </div>
            </div>
            <div class="hb-booking-room-form-group">
                <input type="hidden" name="room-name" value="<?php printf( '%s', $room->name ) ?>" />
                <input type="hidden" name="room-id" value="<?php printf( '%s', $room->post->ID  ) ?>" />
                <input type="hidden" name="action" value="hotel_booking_single_check_room_available"/>
                <?php wp_nonce_field( 'hb_booking_single_room_check_nonce_action', 'hb-booking-single-room-check-nonce-action' ); ?>
                <button type="submit" class="hb_button"><?php esc_html_e( 'Check Available', 'bestel' ); ?></button>
            </div>
        </div>
    </form>

</script> 

<!--Quanity select--> 
<script type="text/html" id="tmpl-hb-room-load-qty">
    <div class="hb-booking-room-form-group">
        <label><?php esc_html_e( 'Quantity Available', 'bestel' ); ?></label>
        <div class="hb-booking-room-form-field hb-form-field-input">
            <select name="hb-num-of-rooms" id="hotel_booking_room_qty" class="number_room_select">
                <option value=""><?php esc_html_e( '--- Quantity ---', 'bestel' ); ?></option>
                <# for( var i = 1; i <= data.qty; i++ ) { #>
                <option value="{{ i }}">{{ i }}</option>
                <# } #>
            </select>
        </div>
    </div>
</script> 

</div>
