<?php
/**
* Widget Functions.
*
* @package Local Supermarket
*/

function local_supermarket_widgets_init(){

	register_sidebar(array(
	    'name' => esc_html__('Main Sidebar', 'local-supermarket'),
	    'id' => 'sidebar-1',
	    'description' => esc_html__('Add widgets here.', 'local-supermarket'),
	    'before_widget' => '<div id="%1$s" class="widget %2$s">',
	    'after_widget' => '</div>',
	    'before_title' => '<h3 class="widget-title"><span>',
	    'after_title' => '</span></h3>',
	));

	register_sidebar(array(
	    'name' => esc_html__('Header Sidebar', 'local-supermarket'),
	    'id' => 'sidebar-header',
	    'description' => esc_html__('Add widgets here.', 'local-supermarket'),
	    'before_widget' => '<div id="%1$s" class="widget %2$s">',
	    'after_widget' => '</div>',
	    'before_title' => '<h3 class="widget-title"><span>',
	    'after_title' => '</span></h3>',
	));


    $local_supermarket_default = local_supermarket_get_default_theme_options();
    $local_supermarket_footer_column_layout = absint( get_theme_mod( 'local_supermarket_footer_column_layout',$local_supermarket_default['local_supermarket_footer_column_layout'] ) );

    for( $i = 0; $i < $local_supermarket_footer_column_layout; $i++ ){
    	
    	if( $i == 0 ){ $count = esc_html__('One','local-supermarket'); }
    	if( $i == 1 ){ $count = esc_html__('Two','local-supermarket'); }
    	if( $i == 2 ){ $count = esc_html__('Three','local-supermarket'); }

	    register_sidebar( array(
	        'name' => esc_html__('Footer Widget ', 'local-supermarket').$count,
	        'id' => 'local-supermarket-footer-widget-'.$i,
	        'description' => esc_html__('Add widgets here.', 'local-supermarket'),
	        'before_widget' => '<div id="%1$s" class="widget %2$s">',
	        'after_widget' => '</div>',
	        'before_title' => '<h2 class="widget-title">',
	        'after_title' => '</h2>',
	    ));
	}

}

add_action('widgets_init', 'local_supermarket_widgets_init');