<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package bestel
 */
get_header();
?>
	<div class="section">
		<div class="container">
			<div class="title-wrap text-center">
			<?php
			if ( isset( $_GET['search-type'] ) ) {
				if ( $_GET['search-type'] == 'room' ) {
					?>
					<h1><?php echo wp_kses_post( esc_html__( 'Rooms Searched Result :', 'bestel' ) ); ?></h1>
					<?php
				}
			} else {
				?>
				<h1><?php echo wp_kses_post( esc_html__( 'Searched Result :', 'bestel' ) ); ?></h1>
			<?php } ?>
			<div class="h-decor"></div>
			</div>
			<div class="row special-grid search-result">
				<?php
				if ( isset( $_GET['search-type'] ) ) {
					$type = $_GET['search-type'];
					if ( $type == 'room' ) {
						$args             = array();
						$args['wp_query'] = array(
							'post_type' => array( 'hb_room' ),
							'orderby'   => 'title',
							'order'     => 'ASC',
						);
						$args['form']     = array( 'action' => home_url( '/' ) );
						$args['fields'][] = array(
							'type'      => 'meta_key',
							'format'    => 'hidden',
							'meta_key'  => 'framework-room-price',
							'compare'   => 'BETWEEN',
							'data_type' => 'NUMERIC',
						);
						$args['fields'][] = array(
							'type'      => 'meta_key',
							'format'    => 'hidden',
							'meta_key'  => 'framework-room-size',
							'compare'   => 'BETWEEN',
							'data_type' => 'NUMERIC',
						);
						$args['fields'][] = array(
							'type'     => 'taxonomy',
							'label'    => 'Room Type',
							'taxonomy' => 'room_types',
							'format'   => 'hidden',
							'operator' => 'IN',
						);
						register_wpas_form( 'adSeach', $args );
						$search = new WP_Advanced_Search( 'adSeach' );
						$search->the_form();
						$wp_query = $search->query();
						if ( $wp_query->have_posts() ) :
							while ( $wp_query->have_posts() ) :
								$wp_query->the_post();
								get_template_part( 'template-parts/content', 'searchroom' );
							endwhile;
						endif;
					}
				} else {
					if ( have_posts() ) :
						while ( have_posts() ) :
							the_post();
							if ( is_page() ) {
								continue;
							}
							get_template_part( 'template-parts/content', get_post_format() );
						endwhile;
					else :
						get_template_part( 'template-parts/content', 'none' );
					endif;
					the_posts_pagination(
						array(
							'prev_text'          => esc_html__( '&laquo; Previous', 'bestel' ),
							'next_text'          => esc_html__( 'Next &raquo;', 'bestel' ),
							'before_page_number' => '',
							'screen_reader_text' => ' ',
						)
					);
				}
				?>
			</div>
		</div>
	</div>
<?php get_footer(); ?>
