<div class="wrap">
    <h2><?php echo __( 'Property Views', 'realia' ); ?></h2>

    <div class="chart-block">
        <div class="chart-title">
            <?php echo __( 'Overall property views for last two weeks', 'realia' ); ?>
        </div><!-- /.chart-title -->

        <div id="chart-statistics-daily">
            <svg></svg>
        </div>
    </div><!-- /.chart-block -->

    <div class="row">
        <div class="one-half">
            <?php $properties = Realia_Statistics::property_views_get_popular_properties(); ?>

            <?php if ( ! empty( $properties ) && is_array( $properties ) ) : ?>
                <table class="table">
                    <thead>
                    <th colspan="2" class="center">
                        <?php echo __( '10 most popular properties', 'realia' ); ?>
                    </th>
                    </thead>

                    <tbody>
                    <?php foreach ( $properties as $property ) : ?>
                        <tr>
                            <td>
                                <?php if ( has_post_thumbnail( $property->key ) ) : ?>
                                    <span class="table-small-image">
											<?php echo get_the_post_thumbnail( $property->key, array( 22, 22 ) ); ?>
										</span><!-- /.table-small-image -->
                                <?php endif; ?>

                                <a href="<?php echo get_the_permalink( $property->key ); ?>"><?php echo get_the_title( $property->key ); ?><a>
                            </td>
                            <td><?php echo esc_attr( $property->count ); ?> <?php echo __( 'views', 'realia' ); ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div><!-- /.one-half -->

        <div class="one-half">
            <?php $locations = Realia_Statistics::property_views_get_popular_locations(); ?>

            <?php if ( ! empty( $locations ) && is_array( $locations ) ) : ?>
                <table class="table">
                    <thead>
                    <th colspan="2" class="center">
                        <?php echo __( '10 most popular locations', 'realia' ); ?>
                    </th>
                    </thead>

                    <tbody>
                    <?php foreach ( $locations as $location ) : ?>
                        <tr>
                            <?php $term = get_term( $location->term_taxonomy_id, 'locations' ); ?>
                            <?php if( $term ): ?>
                                <td>
                                    <?php $term_link = get_term_link( $term->term_taxonomy_id, 'locations' ); ?>

                                    <?php if( ! is_wp_error( $term_link ) ): ?>
                                        <a href="<?php echo $term_link; ?>"><?php echo esc_attr( $term->name ); ?><a>
                                    <?php else: ?>
                                        <?php echo esc_attr( $term->name ); ?>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo esc_attr( $location->count ); ?> <?php echo __( 'views', 'realia' ); ?></td>
                            <?php endif; ?>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div><!-- /.one-half -->
    </div><!-- /.row -->
</div><!-- /.wrap -->