<?php
/**
 * Template part for displaying archive title section
 */

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

global $wp_query;
$post_count = $wp_query->found_posts;
?>
<?php if(!is_front_page()): // Start Archive Title ?>
<div class="rs-container">
    <div class="rs-row">
        <div class="rs-col-6">
            <div class="blog-archive-title">
		        <?php
		        if( is_category() ) {
			        $title = single_cat_title('', false);
			        $sub_title =  rivax_get_option('translate-browse-category')?: esc_html__('Browse Category', 'newsfy');
		        }
                elseif( is_tag() ) {
			        $title = single_tag_title('', false);
			        $sub_title =  rivax_get_option('translate-browse-tag')?: esc_html__('Browse Tag', 'newsfy');
		        }
                elseif( is_tax() ) {
			        $title = single_term_title('', false);
			        $sub_title =  rivax_get_option('translate-browse')?: esc_html__('Browse', 'newsfy');
		        }
                elseif (is_post_type_archive()) {
			        $title = post_type_archive_title( '', false );
			        $sub_title =  rivax_get_option('translate-browse')?: esc_html__('Browse', 'newsfy');
		        }
                elseif( is_search() ) {
			        $title = get_search_query();
			        $sub_title =  rivax_get_option('translate-search-for')?: esc_html__('Search Result for', 'newsfy');
		        }
                elseif( is_author() ) {
					$title = get_the_author();
	                $sub_title =  rivax_get_option('translate-author')?: esc_html__('Author', 'newsfy');
		        }
                elseif( is_home() ) {
                    $title = rivax_get_option('translate-our-articles')?: esc_html__('Our Articles', 'newsfy');
                    $sub_title =  rivax_get_option('translate-browse')?: esc_html__('Browse', 'newsfy');
                }
		        else {
			        $title = get_the_archive_title();
			        $sub_title =  rivax_get_option('translate-browse')?: esc_html__('Browse', 'newsfy');
		        }


		        if(is_author()) {
			        ?>
                    <div class="blog-archive-author-box">
                        <div class="avatar">
					        <?php echo get_avatar( get_the_author_meta( 'user_email' ), 120 ); ?>
                        </div>
                        <div class="desc">
                            <span class="sub-title"><?php echo esc_html($sub_title); ?></span>
                            <h1 class="title"><?php echo esc_html($title); ?></h1>
                            <div class="description"><p><?php the_author_meta( 'description' ); ?></p></div>
                            <div class="rs-row rs-align-items-center">
                                <div class="rs-col-md-4 rs-p-0">
                                    <div class="author-social-links">
								        <?php
								        if(function_exists('rivax_author_social')) {
									        rivax_author_social(get_the_author_meta( 'ID' ));
								        }
								        ?>
                                    </div>
                                </div>
                                <div class="rs-col-md-2 rs-p-0">
                                    <div class="post-count"><span>
                                    <?php
                                    if($post_count > 1) {
                                        $post_count_title = rivax_get_option('translate-articles')?: esc_html__('Articles', 'newsfy');
                                    }
                                    else {
                                        $post_count_title = rivax_get_option('translate-article')?: esc_html__('Article', 'newsfy');
                                    }
                                    echo intval($post_count) . ' ' . esc_html($post_count_title);
                                    ?>
                                    </span></div>
                                </div>
                            </div>
                        </div>
                    </div>
			        <?php
		        }
                elseif(is_search()) {
			        ?>
                    <div class="blog-archive-search">
                        <span class="sub-title"><?php echo esc_html($sub_title); ?></span>
                        <h1 class="title"><?php echo esc_html($title); ?></h1>
                        <div class="rs-row rs-align-items-center">
                            <div class="rs-col-md-4 rs-p-0">
                                <form action="<?php echo esc_url(home_url('/')); ?>" method="get" class="blog-archive-search-form">
                                    <input type="text" name="s" value="<?php echo esc_attr(get_search_query()); ?>" class="search-field" placeholder="<?php echo rivax_get_option('translate-search-3dot')?: esc_attr__('Search ...', 'newsfy'); ?>" aria-label="Search" required>
                                    <button type="submit" class="submit" aria-label="Submit">
                                        <i class="ri-search"></i>
                                    </button>
                                </form>
                            </div>
                            <div class="rs-col-md-2 rs-p-0">
                                <div class="post-count"><span>
                                <?php
                                if($post_count > 1) {
                                    $post_count_title = rivax_get_option('translate-articles')?: esc_html__('Articles', 'newsfy');
                                }
                                else {
                                    $post_count_title = rivax_get_option('translate-article')?: esc_html__('Article', 'newsfy');
                                }
                                echo intval($post_count) . ' ' . esc_html($post_count_title);
                                ?>
                                </span></div>
                            </div>
                        </div>
                    </div>
			        <?php
		        }
		        else {
			        ?>
                    <span class="sub-title"><?php echo esc_html($sub_title); ?></span>
                    <h1 class="title"><?php echo wp_kses_post($title); ?></h1>
			        <?php the_archive_description('<div class="description">', '</div>'); ?>
                    <div class="post-count"><span>
                    <?php
                    if($post_count > 1) {
                        $post_count_title = rivax_get_option('translate-articles')?: esc_html__('Articles', 'newsfy');
                    }
                    else {
                        $post_count_title = rivax_get_option('translate-article')?: esc_html__('Article', 'newsfy');
                    }
                    echo intval($post_count) . ' ' . esc_html($post_count_title);
                    ?>
                    </span></div>
                    <?php
		        }

		        ?>
            </div>
        </div>
    </div>
</div>
<?php endif; // End Archive Title ?>