<?php
/**
 * The template for displaying all single posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 *
 * @package Sparta
 */
$blog_single_content_layout = get_theme_mod('sparta_blog_single_content_layout', 'right-sidebar');
$col_class = array();
if ($blog_single_content_layout !== 'no-sidebar' && is_active_sidebar('sidebar-1')):
    $col_class[] = 'col-lg-9 ';
else:
    $col_class[] = 'col-lg-12 ';
endif;

get_header(); ?>
    <section class="vk-content <?php echo esc_attr($blog_single_content_layout); ?>">
        <div class="vk-banner vk-background-image-1 page-title-bg">
            <div class="vk-background-overlay"></div>
            <div class="container ">
                <div class="vk-banner-wrapper">
                    <?php if (get_post_type() == 'espresso_events'): ?>
                        <div class="page-heading">
                            <h1 class="entry-title"><?php echo esc_html__('Events', 'sparta'); ?></h1>
                        </div>
                    <?php
                    else:
                        if (get_post_type() == 'post'):
                            $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
                            $time_string = sprintf($time_string,
                                esc_attr(get_the_date('c')),
                                esc_html(get_the_date()),
                                esc_attr(get_the_modified_date('c')),
                                esc_html(get_the_modified_date())
                            );
                            echo sprintf(esc_html_x('%s', 'post date', 'sparta'), $time_string);
                        endif;
                        ?>
                        <div class="page-heading">
                            <h1 class="entry-title"><?php the_title(); ?></h1>
                        </div>
                    <?php
                    endif;

                    if (get_post_type() == 'post'):
                        Sparta_Helper::sparta_vk_post_meta_full();
                    else:
                        ?>
                        <div class="vk-breadcrumb">
                            <?php
                            Sparta_Core::get_sparta_template('breadcrumbs');
                            ?>
                        </div>
                    <?php
                    endif;
                    ?>
                </div>
            </div>
        </div>
        <div class="vk-page blog blog-single">
            <div class="container">
                <div class="row">
                    <?php if (get_post_type() !== 'mphb_room_type' && get_post_type() !== 'espresso_events' && is_active_sidebar('sidebar-1')):
                        echo '<div class="'.esc_attr(implode(' ', $col_class)).' prod-content">';
                    else :
                        echo '<div class="col-lg-12">';
                    endif; ?>

                        <?php while (have_posts()) : the_post();
                            if (get_post_type() == 'espresso_events'):
                                get_template_part('template-parts/content', 'event');
                            elseif (get_post_type() === 'mphb_room_type'):
                                get_template_part('template-parts/content', 'roomtype');

                            else:?>
                                <div class="vk-blog-content">
                                    <?php
                                    if (has_post_thumbnail()) {
                                        echo '<div class="vk-blog-thumbnail vk-img-frame">';
                                        the_post_thumbnail();
                                        echo '</div>';
                                    }
                                    ?>
                                    <div class="blog-content">
                                        <?php the_content(); ?>
                                    </div>
                                    <?php if (true == get_theme_mod('sparta_blog_single_show_social_sharing', false)) :
                                        echo '<div class="vk-social-share-box">';
                                        if (class_exists('Univer_Core')) :
                                            echo do_shortcode('[sparta_social_share]');
                                        endif;

                                        echo '</div>';
                                    endif; ?>
                                    <?php
                                    wp_link_pages(array(
                                            'link_before' => '<span>',
                                            'link_after' => '</span>',
                                            'pagelink' => '%',
                                            'before' => '<div class="blog-pagination uni-pagination-content">',
                                            'after' => '</div>',
                                            'nextpagelink' => esc_html__('&rarr;', 'sparta'),
                                            'previouspagelink' => esc_html__('&larr;', 'sparta'),
                                        )
                                    ); ?>
                                    <?php if (has_tag()): ?>
                                        <div class="post-footer-tag">
                                            <div class="heading"><?php echo esc_html__('Tags', 'sparta'); ?></div>
                                            <?php the_tags('', ' ', '<br />'); ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <?php
                                if (true == get_theme_mod('sparta_blog_single_show_post_nav', true)) :
                                    $prev_post = get_previous_post();
                                    $next_post = get_next_post();
                                    ?>
                                    <?php if (!empty($prev_post) || !empty($next_post)): ?>
                                    <div class="post-pagination">
                                        <?php
                                        if (!empty($prev_post)):
                                            $class_prev_thumb = '';
                                            $thumbnail_prev = wp_get_attachment_image_src(get_post_thumbnail_id($prev_post->ID), 'thumbnail');
                                            if(isset($thumbnail_prev) && $thumbnail_prev):
                                            $class_prev_thumb = 'thumb';
                                            endif;
                                            ?>
                                            <div class="prev-post <?php echo esc_attr($class_prev_thumb);?>">
                                                <?php if(isset($thumbnail_prev) && $thumbnail_prev):
                                                    echo '<div class="wap-thumbnav">';
                                                    echo '<a href="'.esc_url(get_permalink($prev_post->ID)).'"><img src="'.esc_url($thumbnail_prev[0]).'" alt="post"></a>';
                                                    echo '</div>';
                                                endif; ?>
                                                <div class="wap-npp">
                                                    <a href="<?php echo esc_url(get_permalink($prev_post->ID)); ?>">
                                                    <div class="heading"><?php echo esc_html__('Previous post', 'sparta'); ?></div>
                                                        <?php echo esc_html($prev_post->post_title); ?>
                                                    </a>
                                                </div>
                                            </div>
                                        <?php endif; ?>
                                        <?php
                                        if (!empty($next_post)):
                                            $class_next_thumb = '';
                                            $thumbnail_next = wp_get_attachment_image_src(get_post_thumbnail_id($next_post->ID), 'thumbnail');
                                            if(isset($thumbnail_next) && $thumbnail_next):
                                                $class_next_thumb = 'thumb';
                                            endif;
                                            ?>
                                            <div class="next-post <?php echo esc_attr($class_next_thumb);?>">
                                                <?php if(isset($thumbnail_next) && $thumbnail_next):
                                                    echo '<div class="wap-thumbnav">';
                                                    echo '<a href="'.esc_url(get_permalink($next_post->ID)).'"><img src="'.esc_url($thumbnail_next[0]).'" alt="post"></a>';
                                                    echo '</div>';
                                                endif; ?>
                                                <div class="wap-npp">
                                                    <a href="<?php echo esc_url(get_permalink($next_post->ID)) ; ?>">
                                                    <div class="heading"><?php echo esc_html__('Next post', 'sparta'); ?></div>
                                                    <?php echo esc_html($next_post->post_title); ?></a>
                                                </div>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                <?php endif;

                                endif;

                                if (comments_open() || get_comments_number()) :
                                    echo '<div class="vk-blog-comment">';
                                    comments_template();
                                    echo '</div>';
                                endif;
                            endif;
                        endwhile; // End of the loop.

                    if (get_post_type() !== 'mphb_room_type' && get_post_type() !== 'espresso_events'):
                        echo '</div>';
                    endif;

                    if (get_post_type() !== 'mphb_room_type' && get_post_type() !== 'espresso_events') :
                        if ($blog_single_content_layout !== 'no-sidebar' && is_active_sidebar('sidebar-1')) :
                            echo '<div class="col-lg-3 prod-sidebar">';
                            get_sidebar();
                            echo '</div>';
                        endif;
                    endif;
                    ?>
                </div>
            </div>
        </div>
    </section>
<?php
get_footer();
