<?php
/**
 * The template for displaying all single posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 * @package United Blog
 */

$single_page_layout = united_blog_get_option('single_page_layout');
$show_single_category = united_blog_get_option('show_single_category', true);
$single_category_color_display = united_blog_get_option('single_category_color_display', 'display_as_bg');
$single_category_limit = united_blog_get_option('single_category_limit', 1);
$single_post_meta = united_blog_get_option('single_post_meta');
$single_post_meta_settings = array(
    'date_format' => united_blog_get_option('single_posts_date_format', 'format_2'),
    'show_icons' => united_blog_get_option('show_single_post_meta_icon', true),
);
get_header(); ?>

<?php while (have_posts()) : the_post(); ?>

    <div class="united-single-affix" tabindex="-1">
        <div class="wrapper-fluid single-affix-wrapper">
            <div class="single-affix-area single-affix-left">
                <div class="single-affix-title"><?php esc_html_e('Current Article:', 'united-blog'); ?></div>
                <h2 class="entry-title entry-title-medium"><?php the_title(); ?></h2>
            </div>
            <div class="single-affix-area single-affix-right hide-on-mobile">
                <div class="entry-meta entry-meta-list">
                <?php united_blog_single_post_comment(); ?>
                </div>
                <?php united_blog_social_share(); ?>
            </div>
        </div>
        <div id="progressBarContainer">
            <div id="united-progressbar"></div>
        </div>
    </div>

    <?php if ($single_page_layout === 'fullwidth_banner_layout') : ?>
        <div class="united-single-banner">
            <?php
            $featured_image_single_post = get_post_meta(get_the_ID(), 'united-blog-meta-checkbox', true);
            if ($featured_image_single_post !== 'yes' && has_post_thumbnail()) : ?>
                <div class="entry-image entry-image-large">
                    <div class="post-thumbnail">
                        <?php
                        the_post_thumbnail('full', array(
                            'alt' => esc_attr(get_the_title())
                        ));
                        ?>
                    </div>
                </div>
            <?php endif; ?>

            <div class="wrapper">
                <header class="entry-header">
                    <?php if ($show_single_category) :
                        united_blog_post_categories($single_category_color_display, $single_category_limit);
                    endif; ?>
                    <h1 class="entry-title entry-title-xlarge"><?php the_title(); ?></h1>
                    <?php united_blog_post_meta_info($single_post_meta, $single_post_meta_settings); ?>
                
                </header>
            </div>
        </div>
    <?php endif; ?>

    <div class="wrapper">
        <div class="row">
            <div id="primary" class="content-area">
                <main id="main" class="site-main">
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <?php if ($single_page_layout === 'content_banner_layout') : ?>
                            <header class="entry-header">
                                <?php if ($show_single_category) :
                                    united_blog_post_categories($single_category_color_display, $single_category_limit);
                                endif; ?>
                                <h1 class="entry-title entry-title-xlarge"><?php the_title(); ?></h1>
                                <div class="entry-meta-single">
                                    <?php united_blog_post_meta_info($single_post_meta, $single_post_meta_settings); ?>
                                </div>
                            </header>

                            <?php
                            $featured_image_single_post = get_post_meta(get_the_ID(), 'united-blog-meta-checkbox', true);
                            if ($featured_image_single_post !== 'yes' && has_post_thumbnail()) : ?>
                                <div class="entry-image">
                                    <div class="post-thumbnail">
                                        <?php
                                        the_post_thumbnail('large', array(
                                            'alt' => esc_attr(get_the_title())
                                        ));
                                        ?>
                                    </div>
                                </div>
                            <?php endif; ?>

                        <?php endif; ?>

                        <div class="entry-content">
                            <?php
                            the_content();
                            wp_link_pages(array(
                                'before' => '<div class="page-links">' . esc_html__('Pages:', 'united-blog'),
                                'after' => '</div>',
                            ));
                            ?>
                        </div>

                        <footer class="entry-footer">
                            <?php united_blog_entry_tags(); ?>
                        </footer>

                        <?php do_action('united_blog_navigation_action'); ?>
                    </article>

                    <?php
                    // Post navigation with previous and next post links
                    the_post_navigation(array(
                        'prev_text' => '<h2 class="united-nav-title nav-title-previous">' . (united_blog_the_theme_svg('arrow-left', $return = true)) . '<span class="screen-text">' . esc_html__('Previous', 'united-blog') . '</span></h2><h3 class="entry-title entry-title-medium">%title</h3>',
                        'next_text' => '<h2 class="united-nav-title nav-title-next"><span class="screen-text">' . esc_html__('Next', 'united-blog') . '</span>' . (united_blog_the_theme_svg('arrow-right', $return = true)) . '</h2><h3 class="entry-title entry-title-medium">%title</h3>',
                    ));

                    // Check if comments are open or there are comments, then load the comment template
                    if (comments_open() || get_comments_number()) :
                        comments_template();
                    endif;
                    ?>

                </main>
            </div>

            <?php get_sidebar(); ?>
        </div>
    </div>

<?php endwhile; ?>

<?php united_blog_single_related_post(); ?>
<?php get_footer(); ?>