<div class="single-property-element property-gallery-wrap">
	<?php
	wp_enqueue_style( 'owl.carousel' );
	wp_enqueue_script( 'owl.carousel' );
	$latest_post_query            = get_posts( "post_type=real-estate&post_status=publish&numberposts=1&order=DESC" );
	$latest_post_id               = is_array( $latest_post_query ) ? $latest_post_query[0]->ID : 0;
	$property_id                  = ! empty( $settings['property_id'] ) ? $settings['property_id'] : $latest_post_id;
	$prop_price_value             = get_post_meta( $property_id, 'property_price_value', true );
	$prop_price_unit              = get_post_meta( $property_id, 'property_price_unit', true );
	$prop_price_prefix            = get_post_meta( $property_id, 'property_price_prefix', true );
	$prop_price_postfix           = get_post_meta( $property_id, 'property_price_postfix', true );
	$prop_enable_short_price_unit = tfre_get_option( 'enable_short_price_unit', 0 ) == 1 ? true : false;
	$prop_address                 = get_post_meta( $property_id, 'property_address', true );
	$prop_size                    = get_post_meta( $property_id, 'property_size', true ) ? get_post_meta( $property_id, 'property_size', true ) : 0;
	$prop_land_area               = get_post_meta( $property_id, 'property_land', true ) ? get_post_meta( $property_id, 'property_land', true ) : 0;
	$prop_rooms                   = get_post_meta( $property_id, 'property_rooms', true ) ? get_post_meta( $property_id, 'property_rooms', true ) : 0;
	$prop_bedrooms                = get_post_meta( $property_id, 'property_bedrooms', true ) ? get_post_meta( $property_id, 'property_bedrooms', true ) : 0;
	$prop_bathrooms               = get_post_meta( $property_id, 'property_bathrooms', true ) ? get_post_meta( $property_id, 'property_bathrooms', true ) : 0;
	$prop_garages                 = get_post_meta( $property_id, 'property_garage', true ) ? get_post_meta( $property_id, 'property_garage', true ) : 0;
	$prop_garages_size            = get_post_meta( $property_id, 'property_garage_size', true ) ? get_post_meta( $property_id, 'property_garage_size', true ) : 0;
	$prop_status                  = get_the_terms( $property_id, 'property-status' );
	$prop_featured                = get_post_meta( $property_id, 'property_featured', true ) ? get_post_meta( $property_id, 'property_featured', true ) : false;
	$prop_gallery_images          = get_post_meta( $property_id, 'gallery_images', true ) ? get_post_meta( $property_id, 'gallery_images', true ) : '';
	$property_gallery             = json_decode( $prop_gallery_images, true );
	$prop_agent_info              = get_post_meta( $property_id, 'property_agent_info', true );
	$agent_post_meta_data         = get_post_custom( $prop_agent_info );
	$user_name                    = $prop_agent_info ? ( isset( $agent_post_meta_data['agent_full_name'] ) ? $agent_post_meta_data['agent_full_name'][0] : '' ) : get_the_author();
	$user_email                   = $prop_agent_info ? ( isset( $agent_post_meta_data['agent_email'] ) ? $agent_post_meta_data['agent_email'][0] : '' ) : '';
	$user_phone_number            = $prop_agent_info ? ( isset( $agent_post_meta_data['agent_phone_number'] ) ? $agent_post_meta_data['agent_phone_number'][0] : '' ) : '';
	$user_position                = $prop_agent_info ? ( isset( $agent_post_meta_data['agent_position'] ) ? $agent_post_meta_data['agent_position'][0] : '' ) : '';
	$user_avatar                  = $prop_agent_info ? ( isset( $agent_post_meta_data['agent_avatar'] ) ? $agent_post_meta_data['agent_avatar'][0] : '' ) : get_the_author_meta( 'profile_image_id', get_the_author_meta( 'ID' ) );
	$no_avatar                    = get_avatar_url( get_the_author_meta( 'ID' ) );
	$default_image_src            = tfre_get_option( 'default_user_avatar', '' )['url'] != '' ? tfre_get_option( 'default_user_avatar', '' )['url'] : $no_avatar;
	$toggle_lazy_load             = tfre_get_option( 'toggle_lazy_load' );
	$measurement_units            = tfre_get_option( 'measurement_units' );

	//setting favorite
	global $current_user;
	wp_get_current_user();
	$check_is_favorite = false;
	$user_id           = $current_user->ID;
	$my_favorites      = get_user_meta( $user_id, 'favorites_property', true );
	if ( ! empty( $my_favorites ) ) {
		$check_is_favorite = array_search( $property_id, $my_favorites );
	}
	$title_not_favorite = $title_favorited = '';
	$icon_favorite     = apply_filters( 'tfre_icon_favorite', 'far fa-bookmark' );
	$icon_not_favorite = apply_filters( 'tfre_icon_not_favorite', 'far fa-bookmark' );

	if ( $check_is_favorite !== false ) {
		$css_class = $icon_favorite;
		$title     = esc_attr__( 'It is your favorite', 'tf-real-estate' );
	} else {
		$css_class = $icon_not_favorite;
		$title     = esc_attr__( 'Add to Favorite', 'tf-real-estate' );
	}
	?>
	<div class="single-property-post <?php echo esc_attr( $settings['style'] ); ?> single-property-post-<?php the_ID(); ?>">
		<div class="featured-single-property style1">
			<?php if ( is_array( $property_gallery ) && count( $property_gallery ) > 1 ) : ?>
				<div class="tfre-property-info">
					<div class="single-property-image-main-1 owl-carousel manual tfre-carousel-manual">
						<?php
						$gallery_id = 'tfre-' . rand();
						foreach ( $property_gallery as $image ) :
							$image_full_src = wp_get_attachment_image_src( $image, 'full' );
							if ( ! empty( $image_full_src ) && is_array( $image_full_src ) ) {
								?>
								<div class="item property-gallery-item tfre-light-gallery">
									<img loading="lazy" src="<?php echo esc_url( $image_full_src[0] ) ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
								</div>
							<?php } ?>
						<?php endforeach; ?>
					</div>
				</div>
				<div class="content-wrapper owl-carousel owl-loaded">
					<div class="content style1">
						<?php if ( $settings['show_group_title'] == true ) : ?>
							<div class="group-title">
								<?php if ( !empty($settings['subtitle']) ) : ?>
									<p><?php echo esc_html( $settings['subtitle'] ); ?></p>
								<?php endif; ?>
								<?php if ( !empty($settings['heading']) ) : ?>
									<h4><?php echo esc_html( $settings['heading'] ); ?></h4>
								<?php endif; ?>
							</div>
						<?php endif; ?>
						<div class="top">
							<?php if ( $prop_featured == true ) : ?>
								<span class="featured-text"><?php esc_html_e( 'Featured', 'tf-real-estate' ); ?></span>
							<?php endif; ?>
							<?php if ( is_array( $prop_status ) ) : ?>
								<span class="status-text"><?php echo esc_html( $prop_status[0]->name, 'tf-real-estate' ); ?></span>
							<?php endif; ?>
						</div>
						<div class="main">
							<div class="heading">
								<h5 class="title">
									<a href="<?php echo esc_url( get_the_permalink( $property_id ) ); ?>"><?php echo esc_attr( get_the_title( $property_id ) ); ?></a>
								</h5>
								<?php if ( $settings['show_address'] == 'yes' ) : ?>
									<div class="address">
										<i class="icon-homeya-location-3"></i>
										<span><?php echo esc_html__( $prop_address ); ?></span>
									</div>
								<?php endif; ?>
							</div>
							<div class="description">
							<?php if ( $settings['show_bedrooms'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-bed2"></i>
						<?php echo  '<span class="value">' . $prop_bedrooms . '</span>'; ?>
					</div>
				<?php endif; ?>
				<?php if ( $settings['show_bathrooms'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-bath3"></i>
						<?php echo '<span class="value">' . $prop_bathrooms . '</span>'; ?>
					</div>
				<?php endif; ?>
				<?php if ( $settings['show_size'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-ruler"></i>
						<?php echo sprintf( '<span class="value">' . tfre_get_format_number( intval( $prop_size ) ) . ' ' . esc_html( $measurement_units) . '</span>'); ?>
					</div>
				<?php endif; ?>
				<?php if ( $settings['show_rooms'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-door"></i>
						<?php echo sprintf( '%s', '<span class="value">' . $prop_rooms . '</span>' ); ?>
					</div>
				<?php endif; ?>
				<?php if ( $settings['show_land_area'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-ruler"></i>
						<?php echo sprintf( '%s', '<span class="value">' . tfre_get_format_number( intval( $prop_land_area ) ) . ' ' . esc_html( $measurement_units) . '</span>' ); ?>
					</div>
				<?php endif; ?>
				<?php if ( $settings['show_garages'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-garage"></i>
						<?php echo sprintf( '%s', '<span class="value">' . $prop_garages . '</span>' ); ?>
					</div>
				<?php endif; ?>
				<?php if ( $settings['show_garages_size'] == 'yes' ) : ?>
					<div class="property-information">
						<i class="icon-homeya-ruler"></i>
						<?php echo sprintf( '%s', '<span class="value">' . tfre_get_format_number( intval( $prop_garages_size ) ) . ' ' . esc_html( $measurement_units) . '</span>' ); ?>
					</div>
				<?php endif; ?>
							</div>
						</div>
						<?php if ( $settings['show_agent'] == 'yes' ) : ?>
							<div class="contact-agent">
								<?php if ( $settings['show_agent'] == 'yes' ) : ?>
									<div class="agent">
										<img alt="<?php echo esc_attr( $user_name ); ?>"
											src="<?php echo esc_attr( tfre_image_resize_id( $user_avatar, '60', '60', true ) ); ?>"
											onerror="this.src = '<?php echo esc_url( $default_image_src ) ?>';"
											class="avatar avatar-96 photo" loading="lazy">
										<div class="agent-information">
											<p class="agent-position"><?php echo esc_html( $user_position ); ?></p>
											<a href="<?php echo esc_url( get_permalink( $prop_agent_info ) ); ?>">
												<p class="agent-name"><?php echo esc_html( $user_name ); ?></p>
											</a>
										</div>
									</div>
								<?php endif; ?>
							</div>
						<?php endif; ?>
						<div class="price-content">
							<span class="price">
								<?php if ( $prop_price_prefix != '' ) : ?>
									<?php echo esc_html__( $prop_price_prefix ); ?>
								<?php endif; ?>
								<?php echo esc_html__( tfre_format_price( $prop_price_value, $prop_price_unit, true, $prop_enable_short_price_unit ) ); ?>
								<?php if ( $prop_price_postfix != '' ) : ?>
									<span><?php echo esc_html__( $prop_price_postfix ); ?></span>
								<?php endif; ?>
							</span>
							<?php if ( $settings['show_action'] == 'yes' ) : ?>

							<ul class="list-controller">
								<li>
									<div class="bookmark">
										<div class="bg-bookmark">
											<a href="javascript:void(0)"
												class="tfre-property-favorite hv-tool <?php esc_attr_e( $check_is_favorite !== false ? 'active' : '' ); ?>"
												data-tfre-data-property-id="<?php echo esc_attr( intval( $property_id ) ); ?>"
												data-toggle="tooltip" data-tooltip="<?php echo esc_attr( $title ) ?>"
												data-tfre-data-title-not-favorite="<?php echo esc_attr_e( 'Add to Favorite', 'tf-real-estate' ); ?>"
												data-tfre-data-title-favorited="<?php echo esc_attr_e( 'It is your favorite', 'tf-real-estate' ); ?>"
												data-tfre-data-icon-not-favorite="<?php echo esc_attr( $icon_not_favorite ); ?>"
												data-tfre-data-icon-favorited="<?php echo esc_attr( $icon_favorite ); ?>">
												<i class="<?php echo esc_attr( $css_class ); ?>"></i>
											</a>
										</div>
									</div>
								</li>
								<li>
									<a class="compare tfre-compare-property hv-tool" href="javascript:void(0)"
										data-property-id="<?php the_ID() ?>" data-toggle="tooltip"
										data-tooltip="<?php echo esc_attr_e( 'Add Compare', 'tf-real-estate' ); ?>"
										title="<?php echo esc_attr_e( 'Compare', 'tf-real-estate' ); ?>">
										<i class="far fa-plus"></i>
									</a>
								</li>
							</ul>

							<?php endif; ?>
						</div>
					</div>
				</div>
			<?php else : ?>
				<?php echo esc_html__( 'You need add an images in gallery for this property.', 'tf-real-estate' ); ?>
			<?php endif; ?>
		</div>
	</div>
</div>