<?php

/**
 * The template for displaying archive pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package WordPress
 * @subpackage NeatNote
 * @since 1.0.0
 */

get_header();

$neatNoteBannerImage = esc_url(get_theme_mod('neatnote_blog_banner_image'));
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if (have_posts()): ?>
        <section id="mainContent" class="NeatNote-BannerSection neatnote_bg NeatNote-text-center NeatNote-BannerViewport NeatNote-altBg neatnote_overlay" <?php echo $neatNoteBannerImage ? 'style="background-image: url(' . $neatNoteBannerImage . '); background-size: cover; background-repeat: no-repeat;"' : 'style="background:var(--primary)"'; ?>>
            <div class="NeatNote-BannerMain">
                <div class="NeatNote-wrapper">
                    <div class="NeatNote-BannerContentMain">

                        <?php
                        if (is_date()):
                            $post_date = get_the_date('d F Y');
                            echo '<h1 class="neatnote-page-title">' . esc_html($post_date) . '</h1>';
                        endif;
                        if (is_tag()):
                            echo '<h1 class="neatnote-page-title">' .  esc_html(single_tag_title('', false)) . '</h1>';
                        endif;
                        if (is_category()) :
                            $category = get_queried_object();
                            echo '<h1 class="neatnote-page-title">' . esc_html($category->name) . '</h1>';
                            // Display category description if available
                            if (!empty($category->description)) :
                        ?>
                                <div class="NeatNote-BannerContent NeatNote-pt20 NeatNote-fontWhite">
                                    <h5><?php echo esc_html($category->description); ?></h5>
                                </div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </section>

        <section class="NeatNote-BlogListingSection NeatNote-p70-0">
            <div class="NeatNote-wrapper">
                <?php if (is_active_sidebar('neatnote-main-sidebar')): ?>
                    <div class="neatnote-page-main-content">
                    <?php endif; ?>
                    <div class="NeatNote-relatedBlogSectionInner <?php echo is_active_sidebar('neatnote-main-sidebar') ? 'neatnoteTwoColmnSec NeatNote-w70' : ''; ?>">
                        <div class="NeatNote-relatedBlogRow">
                            <?php
                            // Start the Loop.
                            while (have_posts()):
                                the_post();
                                get_template_part('template-parts/content/related-blog', 'box');
                            endwhile;
                            ?>
                        </div>
                        <?php if (is_paged() || paginate_links()) : ?>
                            <div class="NeatNote-paginationparent NeatNote-pt100">
                                <?php neatnote_the_posts_navigation();                                ?>
                            </div>
                        <?php endif; ?>
                    </div>

                    <?php if (is_active_sidebar('neatnote-main-sidebar')): ?>
                        <div class="neatnote-page-sidebar-inner NeatNote-w30">
                            <?php get_sidebar(); ?>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
        </section>

    <?php else: ?>
        <?php get_template_part('template-parts/content/content', 'none'); ?>
    <?php endif; ?>

</article>

<?php get_footer(); ?>