<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
global $post;
$view_counter = isset($campoal_options['conikal_view_counter_field']) ? $campoal_options['conikal_view_counter_field'] : 1;

$petition_id = $post->ID;
$address = get_post_meta($petition_id, 'petition_address', true);
$city = get_post_meta($petition_id, 'petition_city', true);
$state = get_post_meta($petition_id, 'petition_state', true);
$country = get_post_meta($petition_id, 'petition_country', true);
$category =  wp_get_post_terms($petition_id, 'petition_category');
?>
<div class="ui basic vertical segment">
    <div class="ui grid">
        <div class="eleven wide column petition-location">
            <div class="truncate text grey"><i class="<?php echo esc_attr(($country || $state || $city) ? 'map marker' : 'tag') ?> icon"></i>
            <?php if(is_array($category) && isset($category[0])) : ?>
                <a href="<?php echo get_term_link($category[0]->term_id) ?>" data-bjax><?php echo esc_html($category[0]->name); ?></a>
            <?php endif; ?>
            <?php if ($country || $state || $city) { ?>
                <?php echo sprintf(esc_html__(' in %s', 'campoal'), esc_html($city ? $city . ', ' : '') . esc_html($state ? $state . ', ' : '') . esc_html($country ? $country : '')); ?>
            <?php } ?>
            </div>
        </div>
        <div class="five wide right aligned column petition-view">
            <?php if ($view_counter == 1 && function_exists('conikal_get_post_views')) { ?>
                <div class="text grey"><i class="eye icon"></i><?php echo sprintf(esc_html__('%s view', 'campoal'), conikal_format_number('%!,0i', (int) conikal_get_post_views($petition_id), true)) ?></div>
            <?php } ?>
        </div>
    </div>
</div>