<?php

/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package WordPress
 * @subpackage NeatNote
 * @since 1.0.0
 */

$featured_img_url = esc_url(get_the_post_thumbnail_url(get_the_ID(), 'full'));
?>

<!-- Start Banner Section -->
<section id="mainContent" class="NeatNote-BannerInnerV1New NeatNote-BannerSection neatnote_bg NeatNote-text-center NeatNote-p80-0 neatnote_overlay NeatNote-fontWhite"
    <?php echo $featured_img_url ? 'style="background-image: url(' . $featured_img_url . ');"' : 'style="background: var(--primary);"'; ?>>
    <div class="NeatNote-BannerMain">
        <div class="NeatNote-wrapper">
            <div class="NeatNote-BannerContentMain">
                <div class="NeatNote-BannerHeading">
                    <h1><?php the_title(); ?></h1>
                </div>
                <div class="NeatNote-BannerContent NeatNote-fontWhite NeatNote-pt20">
                    <div class="NeatNote-BlogAutherTop NeatNote-capitalize">
                        <p><?php echo esc_html__('by ', 'neatnote') . '<span>' . esc_html(get_the_author()) . '</span>' . esc_html__(' On ', 'neatnote') . esc_html(get_the_date('F j, Y')); ?></p>
                    </div>
                    <h5><?php echo esc_html(neatnote_theme_display_read_time()); ?></h5>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="neatnote_blog_main_content neatnote_pt80 NeatNote-pb50">
    <div class="NeatNote-wrapper">
        <div class="neatnote_blog_content_wrapper_parent">
            <?php if (is_active_sidebar('neatnote-sidebar-single-page')): ?>
                <div class="neatnote-page-main-content">
                <?php endif; ?>
                <div class="neatnote_blog_content_wrapper <?php echo is_active_sidebar('neatnote-sidebar-single-page') ? 'NeatNote-w70' : ''; ?>">
                    <?php
                    $neatnote_enable_social_share = get_theme_mod('neatnote_enable_social_share', false);
                    if ($neatnote_enable_social_share === true) {
                        get_template_part('template-parts/social/social', 'share');
                    }
                    ?>
                    <div class="neatnote_content_outer NeatNote-ListStyleDot NeatNote-ib NeatNote-vt" data-aos="fade-up">
                        <div class="neatnote_blog_content_container">
                            <div class="NeatNote-BlogCategoryTop neatnote_noListStyle">
                                <?php
                                $categories = get_the_category();
                                if (!empty($categories)) {
                                    echo '<ul>';
                                    foreach ($categories as $category) {
                                        echo '<li><a href="' . esc_url(get_category_link($category->term_id)) . '">' . esc_html($category->name) . '</a></li>';
                                    }
                                    echo '</ul>';
                                }
                                ?>
                            </div>
                            <div class="neatnoteSignlePostContent">
                                <?php the_content(); ?>
                                <?php
                                wp_link_pages(array(
                                    'before' => '<div class="page-links">' . esc_html__('Pages:', 'neatnote'),
                                    'after'  => '</div>',
                                ));
                                ?>
                            </div>
                            <?php if (has_tag()) : ?>
                                <div class="NeatNote-BlogTagTop neatnote_noListStyle neatnote-pt50">
                                    <h4><?php echo esc_html__('Tags:', 'neatnote'); ?></h4>
                                    <ul class="tags-list">
                                        <?php
                                        $post_tags = get_the_tags();
                                        if ($post_tags) {
                                            foreach ($post_tags as $tag) {
                                                echo '<li><a href="' . esc_url(get_tag_link($tag->term_id)) . '"><span><i class="fa-solid fa-tag"></i></span><span>' . esc_html($tag->name) . '</span></a></li>';
                                            }
                                        }
                                        ?>
                                    </ul>
                                </div>
                            <?php endif; ?>
                        </div>
                        <div class="neatnote_next_prev_container small-NeatNote-wrapper neatnote_d_flex neatnote_justify_space_between neatnote_pt80">
                            <div class="neatnote_prev_blog_container neatnote_d_flex neatnote_gap40" data-aos="fade-up">
                                <div class="neatnote_prev_icon NeatNote-NxtPrvBtn">
                                    <?php previous_post_link('%link', '<i class="fa-solid fa-chevron-left"></i>'); ?>
                                </div>
                                <div class="neatnote_prev_blog_title neatnote_btm_blog_title RubikFont neatNote-fontTheme NeatNote-semibold">
                                    <?php
                                    $previous_post = get_previous_post();
                                    if ($previous_post) {
                                        $trimmed_prev_title = esc_html(wp_trim_words($previous_post->post_title, 5));
                                        previous_post_link('%link', '<span>' . $trimmed_prev_title . '</span>');
                                    }
                                    ?>
                                </div>
                            </div>
                            <div class="neatnote_next_blog_container neatnote_d_flex neatnote_gap40" data-aos="fade-up">
                                <div class="next_blog_title neatnote_btm_blog_title RubikFont neatNote-fontTheme NeatNote-semibold">
                                    <?php
                                    $next_post = get_next_post();
                                    if ($next_post) {
                                        $trimmed_next_title = esc_html(wp_trim_words($next_post->post_title, 5));
                                        next_post_link('%link', '<span>' . $trimmed_next_title . '</span>');
                                    }
                                    ?>
                                </div>
                                <div class="neatnote_next_icon NeatNote-NxtPrvBtn">
                                    <?php next_post_link('%link', '<i class="fa-solid fa-chevron-right"></i>'); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php if (is_active_sidebar('neatnote-sidebar-single-page')): ?>
                    <div class="neatnote-page-sidebar-inner NeatNote-w30">
                        <?php dynamic_sidebar('neatnote-sidebar-single-page'); ?>
                    </div>
                <?php endif; ?>
                </div>
        </div>
    </div>
</section>
<!-- End Of Blog Inner Section -->

<!-- Blog Comment Section -->
<?php if (comments_open() || get_comments_number()) : ?>
    <section class="CommentSection neatnote-p30-0">
        <div class="CommentParent">
            <div class="NeatNote-wrapper">
                <div class="comments_container">
                    <?php comments_template(); ?>
                </div>
            </div>
        </div>
    </section>
<?php endif; ?>