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

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

$check_in_date  = hb_get_request( 'check_in_date' );
$check_out_date = hb_get_request( 'check_out_date' );
$adults         = hb_get_request( 'adults', 0 );
$max_child      = hb_get_request( 'max_child', 0 );
$uniqid         = uniqid();

?>

<div id="hotel-booking-search-<?php echo uniqid(); ?>" class="hotel-booking-search hotel-booking-search-widget">
	<?php

	if (  isset( $atts['show_title'] ) && strtolower( $atts['show_title'] ) == true ) { ?>
    
        <h4><?php esc_html_e( 'Search your room', 'bestel' ); ?></h4>
	<?php } ?>

    <form name="hb-search-form rrr" action="<?php echo hb_get_url(); ?>"
          class="hb-search-form-<?php echo esc_attr( $uniqid ) ?>">
        <ul class="hb-form-table">
            <li class="hb-form-field">
				<?php hb_render_label_shortcode_custom( $atts, 'show_label', esc_html__( 'Arrival Date', 'bestel' ), 'true' ); ?>
                <div class="hb-form-field-input hb_input_field">
                    <input type="text" name="check_in_date" id="check_in_date_<?php echo esc_attr( $uniqid ); ?>"
                           class="hb_input_date_check" value="<?php echo esc_attr( $check_in_date ); ?>"
                           placeholder="<?php esc_attr_e( 'Arrival Date', 'bestel' ); ?>"/>
                </div>
            </li>

            <li class="hb-form-field">
				<?php hb_render_label_shortcode_custom( $atts, 'show_label', esc_html__( 'Departure Date', 'bestel' ), 'true' ); ?>
                <div class="hb-form-field-input hb_input_field">
                    <input type="text" name="check_out_date" id="check_out_date_<?php echo esc_attr( $uniqid ) ?>"
                           class="hb_input_date_check" value="<?php echo esc_attr( $check_out_date ); ?>"
                           placeholder="<?php esc_attr_e( 'Departure Date', 'bestel' ); ?>"/>
                </div>
            </li>

            <li class="hb-form-field">
				<?php hb_render_label_shortcode_custom( $atts, 'show_label', esc_html__( 'Adults', 'bestel' ), 'true' ); ?>
                <div class="hb-form-field-input">
					<?php
					hb_dropdown_numbers(
						array(
							'name'              => 'adults_capacity',
							'min'               => 1,
							'max'               => hb_get_max_capacity_of_rooms(),
							'show_option_none'  => esc_html__( 'Adults', 'bestel' ),
							'selected'          => $adults,
							'option_none_value' => 0,
							'options'           => hb_get_capacity_of_rooms()
						)
					);
					?>
                </div>
            </li>

            <li class="hb-form-field">
				<?php hb_render_label_shortcode_custom( $atts, 'show_label', esc_html__( 'Children', 'bestel' ), 'true' ); ?>
                <div class="hb-form-field-input">
					<?php
					hb_dropdown_numbers(
						array(
							'name'              => 'max_child',
							'min'               => 1,
							'max'               => hb_get_max_child_of_rooms(),
							'show_option_none'  => esc_html__( 'Children', 'bestel' ),
							'option_none_value' => 0,
							'selected'          => $max_child,
						)
					);
					?>
                </div>
            </li>
        </ul>
		<?php wp_nonce_field( 'hb_search_nonce_action', 'nonce' ); ?>
        <input type="hidden" name="hotel-booking" value="results"/>
        <input type="hidden" name="widget-search"
               value="<?php echo isset( $atts['widget_search'] ) ? $atts['widget_search'] : false; ?>"/>
        <input type="hidden" name="action" value="hotel_booking_parse_search_params"/>
        <p class="hb-submit">
            <button type="submit" class="btn btn-primary"><?php esc_html_e( 'CHECK ROOMS', 'bestel' ); ?></button>
        </p>
    </form>
</div>

<?php
function hb_render_label_shortcode_custom( $atts = array(), $name = '', $text = '', $check = '' ) {
		$show = false;
		if (  isset( $atts[ $name ]) && strtolower( $atts[ $name ] ) == $check ) {
			$show = true;
		}
		if ( $show === false ) {
			return;
		}

		echo '<label>' . sprintf( __( '%1$s', 'bestel' ), $text ) . '</label>';
	}
?>