<?php
global $wpestate_curent_fav;
global $wpestate_currency;
global $wpestate_where_currency;
global $show_compare;
global $wpestate_show_compare_only;
global $show_remove_fav;
global $wpestate_options;
global $isdashabord;
global $align;
global $align_class;
global $is_shortcode;
global $is_widget;
global $wpestate_row_number_col;
global $wpestate_full_page;
global $wpestate_listing_type;
global $wpestate_property_unit_slider;
global $wpestate_book_from;
global $wpestate_book_to;
global $wpestate_guest_no;
global $post;

$booking_type       =   wprentals_return_booking_type($post->ID);
$rental_type        =   wprentals_get_option('wp_estate_item_rental_type');




$pinterest          =   '';
$previe             =   '';
$compare            =   '';
$extra              =   '';
$property_size      =   '';
$property_bathrooms =   '';
$property_rooms     =   '';
$measure_sys        =   '';

$col_class  =   'col-md-6';
$col_org    =   4;
$title      =   get_sanitized_truncated_title($post->ID, 0);
$currency_code              =   wprentals_get_option('wp_estate_currency_symbol', '');
if(isset($is_shortcode) && $is_shortcode==1 ){
    $col_class='col-md-'.esc_attr($wpestate_row_number_col).' shortcode-col';
}

if(isset($is_widget) && $is_widget==1 ){
    $col_class='col-md-12';
    $col_org    =   12;
}

if(isset($wpestate_full_page) && $wpestate_full_page==1 ){
    $col_class='col-md-4 ';
    $col_org    =   3;
    if(isset($is_shortcode) && $is_shortcode==1 && $wpestate_row_number_col==''){
        $col_class='col-md-'.esc_attr($wpestate_row_number_col).' shortcode-col';
    }
}

$link               =  esc_url ( get_permalink());
$wprentals_is_per_hour      =   wprentals_return_booking_type($post->ID);



$preview        =   array();
$preview[0]     =   '';
$favorite_class =   'icon-fav-off';
$fav_mes        =   esc_html__( 'add to favorites','wprentals');
if($wpestate_curent_fav){
    if ( in_array ($post->ID,$wpestate_curent_fav) ){
    $favorite_class =   'icon-fav-on';
    $fav_mes        =   esc_html__( 'remove from favorites','wprentals');
    }
}

$listing_type_class='property_unit_v2';
if($wpestate_listing_type==1){
    $listing_type_class='property_unit_v1';
}


global $schema_flag;
if( $schema_flag==1) {
   $schema_data='itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" ';
}else{
   $schema_data=' itemscope itemtype="http://schema.org/Product" ';
}
?>


<div <?php print trim($schema_data);?> class="listing_wrapper <?php print esc_attr($col_class).' '.esc_attr($listing_type_class); ?>  property_flex " data-org="<?php print esc_attr($col_org);?>" data-listid="<?php print esc_attr($post->ID);?>" >

    <?php if( $schema_flag==1) {?>
        <meta itemprop="position" content="<?php print esc_html($prop_selection->current_post);?>" />
    <?php } ?>

    <div class="property_listing "  >
        <?php

            $featured           =   intval  ( get_post_meta($post->ID, 'prop_featured', true) );
            $price_per_guest_from_one       =   floatval( get_post_meta($post->ID, 'price_per_guest_from_one', true) );

            if($price_per_guest_from_one==1){
                $price          =   floatval( get_post_meta($post->ID, 'extra_price_per_guest', true) );
            }else{
                $price          =   floatval( get_post_meta($post->ID, 'property_price', true) );
            }
        
            $property_city      =   get_the_term_list($post->ID, 'property_city', '', ', ', '') ;
            $property_area      =   get_the_term_list($post->ID, 'property_area', '', ', ', '');
            $property_action    =   get_the_term_list($post->ID, 'property_action_category', '', ', ', '');
            $property_categ     =   get_the_term_list($post->ID, 'property_category', '', ', ', '');
            $currency_code      =   wprentals_get_option('wp_estate_currency_symbol', '');

            $preview            =   wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'wpestate_property_listings');
          
            if(isset($preview[0])){
                $thumb_prop         =   '<img itemprop="image" src="'.esc_url($preview[0]).'"   class="b-lazy img-responsive wp-post-image lazy-hidden" alt="'.esc_html__('image','wprentals').'" />';
            }else{
                $thumb_prop_default = wprentals_get_option('wp_estate_default_property_image', 'url');
                if ( empty($thumb_prop_default) ) {
                    $thumb_prop_default = get_stylesheet_directory_uri().'/img/defaultimage_prop.jpg';
                }
                $thumb_prop         =  '<img itemprop="image"  src="'.esc_url($thumb_prop_default).'" class="b-lazy img-responsive wp-post-image  lazy-hidden" alt="'.esc_html__('image','wprentals').'" />';
            }

            ?>


        <div class="listing-unit-img-wrapper">

            <?php
            if( wprentals_get_option('wp_estate_prop_page_new_tab','')=='_self' ){
              print '<a href="'. esc_url($link).'">'. trim($thumb_prop).'</a>';
            }else{
               print '<a href="'. esc_url($link).'" target="_blank">'. trim($thumb_prop).'</a>';
            }
           ?>
            <div class="price_unit_wrapper"> </div>
        </div>


            <div class="title-container">

                <div class="category_name">
                  <?php   include(locate_template('templates/property_card_templates/property_card_title.php'));   ?>
                </div>

                <div class="category_tagline">
                    <?php
                    if ($property_area != '') {
                        print trim($property_area).', ';
                    }
                    print trim($property_city);
                    ?>
                </div>

                <div class="" itemprop="offers" itemscope itemtype="http://schema.org/Offer">    
                    <link itemprop="url" href="<?php echo esc_url($link);?>"/>   
                    <meta itemprop="priceCurrency" content="<?php echo esc_html($currency_code);?>" />
                    <div class="price_unit">
                        <span itemprop="price" content="<?php echo floatval($price);?>">
                        <?php
                            wpestate_show_price($post->ID,$wpestate_currency,$wpestate_where_currency,0);
                            echo '<span class="pernight"> '.wpestate_show_labels('per_night2',$rental_type,$booking_type).'</span>';
                        ?>
                    </div>
                </div>
            </div>




        </div>
    </div>
