<?php
/**
 * The template for displaying a single property within search results loops.
 *
 * Override this template by copying it to yourtheme/propertyhive/content-property.php
 *
 * @author 		PropertyHive
 * @package 	PropertyHive/Templates
 * @version     1.0.0
 */

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

global $property, $propertyhive_loop;

// Store loop count we're currently on
if ( empty( $propertyhive_loop['loop'] ) )
	$propertyhive_loop['loop'] = 0;

// Store column count for displaying the grid
if ( empty( $propertyhive_loop['columns'] ) )
	$propertyhive_loop['columns'] = apply_filters( 'loop_search_results_columns', 1 );

// Ensure visibility
if ( ! $property )
	return;

// Increase loop count
++$propertyhive_loop['loop'];

// Extra post classes
$classes = array('clear');
 $classes[] = 'prop-slide';
if ( 0 == ( $propertyhive_loop['loop'] - 1 ) % $propertyhive_loop['columns'] || 1 == $propertyhive_loop['columns'] )
	$classes[] = 'first';
if ( 0 == $propertyhive_loop['loop'] % $propertyhive_loop['columns'] )
	$classes[] = 'last';
if ( $property->featured == 'yes' )
    $classes[] = 'featured';
?>
<div <?php post_class( $classes ); ?>>

	<?php do_action( 'propertyhive_before_search_results_loop_item' ); ?>
               <?php 
                $gallery_images =$property->get_gallery_attachment_ids();
                            $bedroom = get_post_meta( $post->ID, $key = '_bedrooms', $single = true );
                            $restroom = get_post_meta( $post->ID, $key = '_reception_rooms', $single = true );
                            $bethroom = get_post_meta( $post->ID, $key = '_bathrooms', $single = true );
                            $availability = get_the_terms( $post->ID, 'availability');
                            $property_type = get_the_terms( $post->ID, 'property_type');
                            $address_street = get_post_meta( $post->ID, '_address_street', $single = true);
                            $town_name = get_post_meta( $post->ID, '_address_three', $single = true);
                            $othr_img1 = wp_get_attachment_image_src( $gallery_images['0'], "full" );
               ?> 
                <div class="">
                            <div class="prop-img thumbnail">
                            <a href="<?php the_permalink(); ?>">
                                    <?php
                                    echo '<img src="'.$othr_img1['0'].'" alt="">';
                                ?>
                                <?php if($availability['0']->name){ ?>
                                    <span><?php  echo $availability['0']->name; ?></span>
                                 <?php } ?>
                                <h3><?php echo $property->get_formatted_price(); ?></h3>
                                </a>
                            </div>
                            <div class="details">
                                <a href="<?php the_permalink(); ?>"> 
                                    <?php 
                                    if($town_name && $address_street){
                                        $commasec = ', ';
                                        } 
                                       ?>   
                                    <h2><?php echo $address_street.$commasec.$town_name ?></h2>
                                    <p><?php echo strtolower($bedroom.' bedroom '.$property_type['0']->name) ?></p> 
                                    <?php if($bedroom || $bethroom ){ ?>
                                    <div class="availability-section">
                                        <ul>
                                            <?php if($bedroom){ ?>
                                            <li>
                                                <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/Shape.svg" alt=""> <?php echo $bedroom ?></li>
                                            <?php } 
                                            if($bethroom){
                                            ?>  
                                                <li>
                                                   <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/bthrooms.svg" alt=""> <?php echo $bethroom; ?>
                                                </li>
                                            <?php }  if($restroom){ ?>  
                                                <li> <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/sofa.svg" alt=""> <?php echo  $restroom; ?></li>
                                            <?php } ?>
                                        </ul>   
                                    </div>
                                    <?php } ?>
                                </a>   
                            </div>
                        </div>
    
	<?php do_action( 'propertyhive_after_search_results_loop_item' ); ?>

</div>