<?php
/**
 * Theme Sidebars
 */

if(!function_exists('cookandmeal_sidebars_init')):
function cookandmeal_sidebars_init() {

    register_sidebar(
      array(
        'name' => esc_html__( 'Default Blog sidebar', 'cookandmeal' ),
        'id' => 'main-sidebar',
        'description' => esc_html__( 'Widgets in this area will be shown in the left or right site column on: Main Blog page, Archives, Search.', 'cookandmeal' )
      )
    );

    register_sidebar(
      array(
        'name' => esc_html__( 'Single Blog Post sidebar', 'cookandmeal' ),
        'id' => 'post-sidebar',
        'description' => esc_html__( 'Widgets in this area will be shown in the left or right site column on: Single Blog Post.', 'cookandmeal' )
      )
    );

    register_sidebar(
      array(
        'name' => esc_html__( 'Page sidebar', 'cookandmeal' ),
        'id' => 'page-sidebar',
        'description' => esc_html__( 'Widgets in this area will be shown in the left or right site column on: Page.', 'cookandmeal' )
      )
    );

    register_sidebar(
      array(
        'name' => esc_html__( 'WooCommerce sidebar', 'cookandmeal' ),
        'id' => 'woocommerce-sidebar',
        'description' => esc_html__( 'Widgets in this area will be shown in the left or right site column for woocommerce pages.', 'cookandmeal' )
      )
    );

    register_sidebar(
      array(
        'name' => esc_html__( 'WooCommerce product sidebar', 'cookandmeal' ),
        'id' => 'woocommerce-product-sidebar',
        'description' => esc_html__( 'Widgets in this area will be shown in the left or right site column for woocommerce single product pages.', 'cookandmeal' )
      )
    );

    register_sidebar(
      array(
        'name' => esc_html__( 'Footer sidebar', 'cookandmeal' ),
        'id' => 'footer-sidebar',
        'description' => esc_html__( 'Widgets in this area will be shown in site footer in 4 column.', 'cookandmeal' )
      )
    );

    // Mega Menu sidebars
    if(get_theme_mod('module_megamenu_sidebars', 1) > 0) {
        for ($i = 1; $i <= get_theme_mod('module_megamenu_sidebars', 1); $i++) {
            register_sidebar(
              array(
                'name' => esc_html__( 'Mega Menu sidebar #', 'cookandmeal' ).$i,
                'id' => 'megamenu_sidebar_'.$i,
                'description' => esc_html__( 'You can use this sidebar to display widgets inside megamenu items in menus.', 'cookandmeal' )
              )
            );
        }
    }

}
endif;
add_action( 'widgets_init', 'cookandmeal_sidebars_init' );
