<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Sparta
 */

get_header();
$page_title_class = '';
if (function_exists('is_cart') && function_exists('is_checkout') && function_exists('is_account_page')) :
    if (is_cart() || is_checkout() || is_account_page()) :
        $page_title_class = 'page-title-product';
    endif;
endif;

$sparta_page_layout = get_theme_mod('sparta_standard_page_sidebar_layout', 'right-sidebar');
$hidden_page_title = get_post_meta($post->ID, 'univer_hidden_page_title', true);
$meta_page_layout = get_post_meta($post->ID, 'univer_sidebar_layout', true);

$layout_container_class = $sidebar_layout = '';
$col_class = array();

if ($meta_page_layout !== '' && $meta_page_layout !== 'default'):
    if ($meta_page_layout === 'full-screen'):
        $layout_container_class = 'container';
        $col_class[] = 'col-lg-12 ';
    else:
        $layout_container_class = 'container';
        if ($meta_page_layout !== 'no-sidebar' && is_active_sidebar('sidebar-1')):
            $col_class[] = 'col-lg-9 ';
        else:
            $col_class[] = 'col-lg-12 ';
        endif;
    endif;

    $sidebar_layout = $meta_page_layout;

else:
    if ( function_exists('is_account_page') && is_account_page() || function_exists('is_cart') && is_cart() || function_exists('is_checkout') && is_checkout()):
        $layout_container_class = 'container';
        $col_class[] = 'col-lg-12 ';
    else:
        if ($sparta_page_layout === 'full-screen'):
            $layout_container_class = 'container';
            $col_class[] = 'col-lg-12 ';
        else:
            $layout_container_class = 'container';
            if ($sparta_page_layout !== 'no-sidebar' && is_active_sidebar('sidebar-1')):
                $col_class[] = 'col-lg-9 ';
            else:
                $col_class[] = 'col-lg-12 ';
            endif;

        endif;

        $sidebar_layout = $sparta_page_layout;

    endif;
endif;
?>
    <section class="vk-content <?php echo esc_attr($sidebar_layout); ?>">
        <?php if (!is_front_page() && !is_home() && $hidden_page_title !== 'yes') : ?>
            <div class="vk-banner vk-background-image-4 page-title-bg <?php echo esc_attr($page_title_class); ?>">
                <div class="vk-background-overlay"></div>
                <div class="container ">
                    <div class="vk-banner-wrapper">
                        <div class="page-heading">
                            <?php the_title('<h1 class="entry-title">', '</h1>'); ?>
                        </div>
                        <div class="vk-breadcrumb">
                            <?php
                            Sparta_Core::get_sparta_template('breadcrumbs');
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="vk-page shop">
            <div class="<?php echo esc_attr($layout_container_class); ?>">
                <div class="row">
                    <div class="<?php echo esc_attr(implode(' ', $col_class)); ?> prod-content">
                        <?php
                        while (have_posts()) : the_post();

                            get_template_part('template-parts/content', 'page');

                            // If comments are open or we have at least one comment, load up the comment template.
                            if (comments_open() || get_comments_number()) :
                                comments_template();
                            endif;

                        endwhile; // End of the loop.
                        ?>
                    </div>
                    <?php
                    if ($meta_page_layout === ''):
                        if (function_exists('is_account_page') && is_account_page() || function_exists('is_cart') && is_cart() || function_exists('is_checkout') && is_checkout()):
                        else:
                            if ($sparta_page_layout === 'left-sidebar' || $sparta_page_layout === 'right-sidebar'):
                                ?>
                                <div class="col-lg-3 prod-sidebar">
                                    <?php get_sidebar(); ?>
                                </div>
                            <?php
                            endif;
                        endif;
                    else:
                        if (function_exists('is_account_page') && is_account_page() || function_exists('is_cart') && is_cart() || function_exists('is_checkout') && is_checkout()):
                        else:
                            if ($meta_page_layout === 'right-sidebar' || $meta_page_layout === 'left-sidebar' || ($meta_page_layout === 'default' && $sparta_page_layout === 'left-sidebar') || ($meta_page_layout === 'default' && $sparta_page_layout === 'right-sidebar') && is_active_sidebar('sidebar-1')):
                                ?>
                                <div class="col-lg-3 prod-sidebar">
                                    <?php get_sidebar(); ?>
                                </div>
                            <?php
                            endif;
                        endif;
                    endif;
                    ?>
                </div>
            </div>
        </div>
    </section>
<?php
get_footer();
