<?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'] : 0;

$post_categories = get_the_category();
?>

<div class="ui header post-labels">
    <?php if ( is_sticky() ) { ?>
        <span class="ui primary label post-stick-label"><i class="pin icon"></i><?php esc_html_e('Pinned', 'campoal') ?></span>
    <?php } ?>
    <?php if ($post_categories) {
        foreach($post_categories as $id => $post_category) {
            if ($id < 2) { ?>
            <a class="ui primary label" href="<?php echo esc_url($post_category ? get_term_link($post_category->term_id) : '') ?>" data-bjax>
                <?php echo esc_html($post_category ? $post_category->name : '') ?>
            </a>
        <?php  }
        } ?>
        <?php if (count($post_categories) > 2) {
            $more_cats_number = count($post_categories) - 2; ?>
            <button class="ui basic label post-more-categories" href="<?php echo esc_url($post_category ? get_term_link($post_category->term_id) : '') ?>">
                <?php echo sprintf(_n('%s+ category', '%s+ categories', $more_cats_number, 'campoal'), $more_cats_number ) ?>
        </button>
            <div class="more-categories ui bottom right popup">
                <div class="ui primary labels">
                <?php foreach($post_categories as $id => $post_category) {
                    if ($id >= 2) { ?>
                    <a class="ui label" href="<?php echo esc_url($post_category ? get_term_link($post_category->term_id) : '') ?>" data-bjax>
                        <?php echo esc_html($post_category ? $post_category->name : '') ?>
                    </a>
                <?php  }
                } ?>
                </div>
            </div>
        <?php } ?>
    <?php } ?>

    <?php if (function_exists('conikal_get_post_views')) {
    if ($view_counter == 1 && !empty((int) conikal_get_post_views($post->ID))) { ?>
        <span class="ui basic label">
            <?php echo sprintf( _n('%s view', '%s views', (int) conikal_get_post_views($post->ID), 'campoal'), conikal_format_number('%!,0i', (int) conikal_get_post_views($post->ID), true) ); ?>
        </span>
    <?php }
    } ?>

    <span class="ui basic label">
        <i class="time icon"></i><?php echo conikal_reading_time($post->ID) ?>
    </span>
</div>