<?php

/**
 * Register theme sidebars
 * @package Glaciers
 * @since 1.0.0
 */

if (!defined('ABSPATH')) {
	exit; // Exit if accessed directly.
}

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

		register_sidebar(array(
			'name' => esc_html__('Blog Sidebar', 'glaciers'),
			'id' => 'blog-sidebar',
			'description' => esc_html__('Sidebar for your blog and archives.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		));
		register_sidebar(array(
			'name' => esc_html__('Page Right Sidebar', 'glaciers'),
			'id' => 'right-sidebar',
			'description' => esc_html__('Right sidebar for your pages.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		));
		register_sidebar(array(
			'name' => esc_html__('Page Left Sidebar', 'glaciers'),
			'id' => 'left-sidebar',
			'description' => esc_html__('Left sidebar for your pages.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		));

		register_sidebar(array(
			'name' => esc_html__('Banner', 'glaciers'),
			'id' => 'banner',
			'description' => esc_html__('Banner sidebar for images and sliders.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="banner widget %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h2 class="widget-title">',
			'after_title' => '</h2>',
		));

		register_sidebar(array(
			'name'          => esc_html__('Bottom 1', 'glaciers'),
			'id'            => 'bottom1',
			'description'   => esc_html__('First sidebar of the bottom group located above the footer area.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		));

		register_sidebar(array(
			'name'          => esc_html__('Bottom 2', 'glaciers'),
			'id'            => 'bottom2',
			'description'   => esc_html__('Second sidebar of the bottom group located above the footer area.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		));

		register_sidebar(array(
			'name'          => esc_html__('Bottom 3', 'glaciers'),
			'id'            => 'bottom3',
			'description'   => esc_html__('Third  sidebar of the bottom group located above the footer area.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		));

		register_sidebar(array(
			'name'          => esc_html__('Bottom 4', 'glaciers'),
			'id'            => 'bottom4',
			'description'   => esc_html__('Fourth sidebar of the bottom group located above the footer area.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		));

		register_sidebar(array(
			'name' => esc_html__('Footer', 'glaciers'),
			'id' => 'footer',
			'description' => esc_html__('Add a widget to your footer area.', 'glaciers'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		));
	}
endif;
add_action('widgets_init', 'glaciers_widgets_init');



/*----------------------------------------------------------------------------------------------- 
	Grouped Sidebars - Bottom
	This will add classes based on how many sidebars are active.
	@since 1.0.0
--------------------------------------------------------------------------------------------------- */
function glaciers_bottom_group()
{
	$count = 0;
	if (is_active_sidebar('bottom1'))
		$count++;
	if (is_active_sidebar('bottom2'))
		$count++;
	if (is_active_sidebar('bottom3'))
		$count++;
	if (is_active_sidebar('bottom4'))
		$count++;
	$class = '';
	switch ($count) {
		case '1':
			$class = 'col-md-12 widget-area';
			break;
		case '2':
			$class = 'col-md-6 widget-area';
			break;
		case '3':
			$class = 'col-md-4 widget-area';
			break;
		case '4':
			$class = 'col-sm-12 col-md-6 col-lg-3 widget-area';
			break;
	}
	if ($class)
		echo 'class="' . esc_attr($class) . '"';
}
