<?php
/**
 * Archive Real Estate Template
 *
 * @package Immowp_Gestion_Immobiliere
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require dirname( __DIR__ ) . '/archive/property-query.php';



?>
<div class="iwp__property">
	<?php require __DIR__ . '/archive-parts/advanced-search.php'; ?>
	
	<div class="iwp__property-listing">
		<div class="iwp__listing-header">
			<div class="iwp__listing-header-info">
				<h2 class="iwp__results-count">
					<?php echo esc_html( $immowp_query->found_posts ); ?> 
					<span><?php ( $immowp_query->found_posts > 1 ? esc_html_e( 'Biens', 'immowp-gestion-immobiliere' ) : esc_html_e( 'Bien', 'immowp-gestion-immobiliere' ) ); ?></span>
				</h2>

			</div>
			
			<div class="iwp__listing-header-actions">
				<form action="" method="get" class="iwp__sort-form">
					<input type="hidden" name="reference" value="<?php echo esc_attr( $immowp_reference ); ?>" />
					<input type="hidden" name="offre" value="<?php echo esc_attr( $immowp_offre_selected_value ); ?>" />
					<input type="hidden" name="type_bien" value="<?php echo esc_attr( $immowp_type_selected_value ); ?>" />
					<input type="hidden" name="localisation" value="<?php echo esc_attr( $immowp_localisation_selected_value ); ?>" />

					<div class="iwp__select-simple">
						<select name="sort" onchange="this.form.submit()">
							<option value=""><?php esc_html_e( 'Trier par', 'immowp-gestion-immobiliere' ); ?></option>
							<option value="prix-asc" <?php echo( $immowp_sort == 'prix-asc' ? 'selected' : '' ); ?>><?php esc_html_e( 'Prix croissant', 'immowp-gestion-immobiliere' ); ?></option>
							<option value="prix-desc" <?php echo( $immowp_sort == 'prix-desc' ? 'selected' : '' ); ?>><?php esc_html_e( 'Prix décroissant', 'immowp-gestion-immobiliere' ); ?></option>
						</select>
					</div>
				</form>
			</div>
		</div>

		<div class="iwp__property-listing__results">

			<?php if ( $immowp_query->have_posts() ) : ?>
				<div class="iwp__items">
					<?php
					while ( $immowp_query->have_posts() ) :
						$immowp_query->the_post();
						include __DIR__ . '/archive-parts/property-item.php';
						endwhile;
					?>
				</div>
			<?php else : ?>
				<div class="iwp_noresults">
					<?php echo esc_html( get_option( 'immowp_archive_text' ) ); ?>
				</div>
			<?php endif; ?>

			<div class="iwp__property-pagination">
				<?php
				$immowp_big = 999999999;

				$immowp_pagination = paginate_links(
					array(
						'base'      => str_replace( $immowp_big, '%#%', esc_url( get_pagenum_link( $immowp_big ) ) ),
						'format'    => '?paged=%#%',
						'current'   => max( 1, $immowp_paged ),
						'total'     => $immowp_query->max_num_pages,
						'prev_text' => '«',
						'next_text' => '»',
					)
				);
				
				if ( $immowp_pagination ) {
					echo wp_kses_post( $immowp_pagination );
				}
				?>
			</div>
		</div>
	</div>
</div>
<?php wp_reset_postdata(); ?>
