<?php
/**
 * The right sidebar containing the main widget area
 *
 * @package Magazine Style
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

// when both sidebars turned on reduce col size to 3 from 4.
$sidebar_pos = get_theme_mod('magazinestyle_sidebar_position');
$layoutmeta = get_post_meta(get_the_ID(), '_singlepost_magazinestyle', true);
$layoutmetapage = get_post_meta(get_the_ID(), '_pagepost_magazinestyle', true);
$col_size = 'col-md-4'; // Default column size

if (('lr' === $layoutmeta && is_single()) || ('lr' === $layoutmetapage && is_page()) || 'both' === $sidebar_pos) {
    $col_size = 'col-md-3'; // Reduce column size to 3
}

?>
<div class="<?php echo $col_size; ?> widget-area" id="right-sidebar"  <?php magazinestyle_do_schema( 'sidebar' ); ?>>
<?php // dynamic_sidebar('right-sidebar'); ?>

<?php if ( ! dynamic_sidebar( 'right-sidebar' ) ) : ?>

<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside><!-- #search -->

<aside id="archives" class="widget">
<h3 class="widget-title"><?php _e( 'Archives', 'magazine-style' ); ?></h3>
<ul>
    <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside><!-- #archives -->

<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'magazine-style' ); ?></h3>
<ul>
    <?php wp_register(); ?>
    <li><?php wp_loginout(); ?></li>
    <?php wp_meta(); ?>
</ul>
</aside><!-- #meta -->

<?php endif; ?>
</div><!-- #right-sidebar -->
