<?php
if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly

// We can pass $args or get meta from option panel
$single_meta = rivax_get_option('single-post-meta');

if(!$single_meta) {
    $single_meta = array(
        'category'      => true,
        'author-avatar' => true,
        'author-name'   => true,
        'date'          => true,
        'date-updated'  => false,
        'reading-time'  => false,
        'views'         => false,
        'comments'      => true,
        'excerpt'       => false,
    );
}

$show_category = $single_meta['category'];
$show_author_avatar = $single_meta['author-avatar'];
$show_author_name = $single_meta['author-name'];
$show_date = $single_meta['date'];
$show_date_updated = $single_meta['date-updated'];
$show_reading_time = $single_meta['reading-time'];
$show_views = $single_meta['views'];
$show_comments = $single_meta['comments'];
$show_excerpt = $single_meta['excerpt'];
?>
<div class="single-hero-title">
    <?php
    $badge_text = get_post_meta(get_the_ID(), 'rivax_single_title_badge', true);
    if($badge_text) {
	    echo '<span class="single-title-badge">' . esc_html($badge_text) . '</span>';
    }
    ?>
    <?php rivax_breadcrumb(); ?>
    <?php if( $show_category ): ?>
	    <?php
        $cls = rivax_get_option('single-category-style')?: 'style-1';
        if(in_array($cls, ['style-1', 'style-2']) && rivax_get_option('single-category-skew')) {
            $cls .= ' skew-bg';
        }
        ?>
        <div class="category <?php echo esc_attr($cls); ?>">
            <?php
            $categories = get_the_category();
            $max = intval(rivax_get_option('max-category-show'))?: 100;
            $count = 0;
            foreach ($categories as $category) {
                $count++;
                echo '<a class="term-id-' . $category->term_id . '" href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( $category->name ) . '"><span>' . esc_html( $category->name ) . '</span></a>';
                if( $count >= $max ) { break; };
            }
            ?>
        </div>
    <?php endif; ?>

    <h1 class="title"><?php the_title(); ?></h1>
    <?php
    if( $show_excerpt ) {
	    $excerpt = rivax_get_the_excerpt(200);
	    if ($excerpt) {
		    echo '<p class="excerpt">' . $excerpt . '</p>';
	    }
    }
    ?>
    <div class="single-hero-meta">
        <?php if( $show_author_avatar ): ?>
            <div class="meta-1">
                <a target="_blank" class="author-avatar" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta( 'ID' ))); ?>">
                    <?php echo get_avatar( get_the_author_meta( 'user_email' ), 45 ); ?>
                </a>
            </div>
        <?php endif; ?>

        <div class="meta-2">
            <div class="top">
                <?php if( $show_author_name ): ?>
                    <a target="_blank" class="author-name" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta( 'ID' ))); ?>">
                        <?php echo esc_html(get_the_author()); ?>
                    </a>
                <?php endif; ?>
            </div>
            <div class="bottom">
                <?php if( $show_date ): ?>
                    <span class="meta-item date">
                        <?php echo get_the_date(); ?>
                    </span>
                <?php endif; ?>

                <?php if( $show_date_updated && (get_the_date() != get_the_modified_date()) ): ?>
                    <span class="meta-item date-updated">
                        <?php echo esc_html__('Updated on ', 'newsfy') . get_the_modified_date(); ?>
                    </span>
                <?php endif; ?>

                <?php if( $show_reading_time ): ?>
                    <span class="meta-item reading-time">
                        <?php
                        $mins = rivax_get_reading_time();
                        if($mins > 1) {
                            echo intval($mins) . ' ';
                            echo rivax_get_option('translate-min-read')?: esc_html__('Min Read', 'newsfy');
                        }
                        else {
                            echo rivax_get_option('translate-one-min-read')?: esc_html__('One Min Read', 'newsfy');
                        }
                        ?>
                    </span>
                <?php endif; ?>
            </div>
        </div>
        <div class="meta-3">
		    <?php if( $show_views ): ?>
                <span class="meta-item views" title="<?php echo rivax_get_option('translate-views')?: esc_attr__('Views', 'newsfy'); ?>">
                        <i class="ri-fire"></i>
                        <span class="count"><?php echo rivax_get_post_views(get_the_ID()); ?></span>
                    </span>
		    <?php endif; ?>

		    <?php if( $show_comments ): ?>
                <span class="meta-item comments" title="<?php echo rivax_get_option('translate-comments')?: esc_attr__('Comments', 'newsfy'); ?>">
                        <i class="ri-chat"></i>
                        <span class="count"><?php echo intval(get_comments_number()); ?></span>
                    </span>
		    <?php endif; ?>
        </div>
    </div>
</div>
