<?php
get_header();

$page_extra_class = ! empty( get_post_meta( get_the_ID(), 'page_extra_class', true ) ) ? get_post_meta( get_the_ID(), 'page_extra_class', true ) : '';
$page_layout      = ! empty( get_post_meta( get_the_ID(), 'page_sidebar_layout', true ) ) ? get_post_meta( get_the_ID(), 'page_sidebar_layout', true ) : 'left';
$sidebar_id       = ! empty( get_post_meta( get_the_ID(), 'page_sidebar', true ) ) ? get_post_meta( get_the_ID(), 'page_sidebar', true ) : 'widget-area';

$sidebar_isset = wp_get_sidebars_widgets();
if ( empty( $sidebar_isset[ $sidebar_id ] ) ) {
	$page_layout = 'full';
}
$main_container_class   = array( 'main-container' );
$main_container_class[] = $page_extra_class;
$main_content_class     = array( 'main-content', 'col-12' );

if ( $page_layout != 'full' ) {
	$main_container_class[] = $page_layout . '-sidebar has-sidebar';
	$main_content_class[]   = 'col-xl-9 col-lg-8';
} else {
	$main_container_class[] = 'no-sidebar';
}
?>
    <main id="content" class="site-main <?php echo esc_attr( implode( ' ', $main_container_class ) ); ?>">
        <div class="container">
            <div class="row">
                <div class="<?php echo esc_attr( implode( ' ', $main_content_class ) ); ?>">
					<?php
					if ( have_posts() ) {
						while ( have_posts() ) {
							the_post();
							?>
                            <div class="page-main-content">
								<?php
								the_content();
								wp_link_pages( array(
										'before'      => '<div class="page-links"><span class="page-links-title">' . esc_html__( 'Pages:', 'draly-dropshipping-starter' ) . '</span>',
										'after'       => '</div>',
										'link_before' => '<span>',
										'link_after'  => '</span>',
										'pagelink'    => '<span class="screen-reader-text">' . esc_html__( 'Page', 'draly-dropshipping-starter' ) . ' </span>%',
										'separator'   => '<span class="screen-reader-text">, </span>',
									)
								);
								?>
                            </div>
							<?php
							// 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;
						}
					}
					?>
                </div>
				<?php
				if ( $page_layout != 'full' ) {
					if ( is_active_sidebar( $sidebar_id ) ) : ?>
                        <div class="sidebar col-xl-3 col-lg-4 col-12">
                            <div id="widget-area" class="widget-area sidebar-page">
								<?php dynamic_sidebar( $sidebar_id ); ?>
                            </div>
                        </div>
					<?php endif;
				}
				?>
            </div>
        </div>
    </main>
<?php get_footer();