<?php $paged = ( get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php $permalink = get_the_permalink(); ?>
<?php $favorites = get_user_meta( get_current_user_id(), 'favorites', true ); ?>
<?php $favorites = ( ! is_array( $favorites ) ||  count( $favorites ) == 0 ) ? array( '', ) : $favorites; ?>

<?php query_posts( array(
	'post_type'     => 'property',
	'paged'         => $paged,
	'post__in'		=> $favorites,
) ); ?>

<?php if ( have_posts() ) : ?>
	<table class="property-table">
		<tbody>
		<?php while ( have_posts() ) : the_post(); ?>
			<tr>
				<td class="property-table-info">
					<?php if ( has_post_thumbnail() ) : ?>
						<a href="<?php the_permalink(); ?>" class="property-table-info-image">
							<?php the_post_thumbnail(); ?>
						</a><!-- /.property-table-info-image -->
					<?php endif; ?>

					<div class="property-table-info-content">
						<div class="property-table-info-content-title">
							<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
						</div><!-- /.property-table-info-content-title -->

						<?php $location = Realia_Query::get_property_location_name(); ?>
						<?php if ( ! empty ( $location ) ) : ?>
							<div class="property-table-info-content-location">
								<?php echo wp_kses( $location, wp_kses_allowed_html( 'post' ) ); ?>
							</div><!-- /.property-table-info-content-location -->
						<?php endif; ?>

						<?php $price = Realia_Price::get_property_price(); ?>
						<?php if ( ! empty( $price ) ) : ?>
							<div class="property-table-info-content-price">
								<?php echo wp_kses( $price, wp_kses_allowed_html( 'post' ) ); ?>
							</div><!-- /.property-table-info-content-price -->
						<?php endif; ?>
					</div><!-- /.property-table-info-content -->
				</td>

				<td class="min-width nowrap">
					<a href="<?php echo get_site_url(); ?>?favorites-remove=true&id=<?php the_ID(); ?>" class="btn-alert favorite-button-delete"><i class="fa fa-times"></i></a>
				</td>
			</tr>
		<?php endwhile; ?>
		</tbody>
	</table>

	<div class="nav-previous alignleft"><?php next_posts_link( __( 'Older posts', 'realia' ) ); ?></div>
	<div class="nav-next alignright"><?php previous_posts_link( __( 'Newer posts', 'realia' ) ); ?></div>
<?php else : ?>
	<div class="alert alert-warning">
		<p><?php echo __( 'You don\'t have any favorite properties, yet. Start by adding some.', 'realia' )?></p>
	</div>
<?php endif; ?>