<?php
/**
 * Widget FUnctions.
 *
 * @package Vintuna
 */
/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function vintuna_widgets_init(){

    $vintuna_default = vintuna_get_default_theme_options();

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

    register_sidebar( array(
        'name' => esc_html__('Offcanvas Widget', 'vintuna'),
        'id' => 'vintuna-offcanvas-widget',
        'description' => esc_html__('Add widgets here.', 'vintuna'),
        'before_widget' => '<div id="%1$s" class="widget theme-widget-default %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<header class="theme-widget-header"><h3 class="widget-title">',
        'after_title' => '</h3><span class="block-title-dash"></span></header>',
    ));

    $wpi_vintuna_home_sections_2 = get_theme_mod('wpi_vintuna_home_sections_2', json_encode($vintuna_default['wpi_vintuna_home_sections_2']));
    $wpi_vintuna_home_sections_2 = json_decode($wpi_vintuna_home_sections_2);

    foreach( $wpi_vintuna_home_sections_2 as $vintuna_home_section ){

        $home_section_type = isset( $vintuna_home_section->home_section_type ) ? $vintuna_home_section->home_section_type : '';

        switch( $home_section_type ){

            case 'home-widget-area':

                $ed_home_widget_area = isset( $vintuna_home_section->section_ed ) ? $vintuna_home_section->section_ed : '';

                if( $ed_home_widget_area == 'yes' ){

                    register_sidebar(array(
                        'name' => esc_html__('Front Page Widget Area', 'vintuna'),
                        'id' => 'front-page-widget-area-1',
                        'description' => esc_html__('Add widgets here.', 'vintuna'),
                        'before_widget' => '<div id="%1$s" class="widget %2$s">',
                        'after_widget' => '</div>',
                        'before_title' => '<header class="theme-widget-header"><h3 class="widget-title">',
                        'after_title' => '</h3><span class="block-title-dash"></span></header>',
                    ));

                }

                break;

            default:

                break;

        }

    }

    $vintuna_default = vintuna_get_default_theme_options();
    $footer_column_layout = absint(get_theme_mod('footer_column_layout', $vintuna_default['footer_column_layout']));

    for( $i = 0; $i < $footer_column_layout; $i++ ){

        if ($i == 0) {
            $count = esc_html__('One', 'vintuna');
        }
        if ($i == 1) {
            $count = esc_html__('Two', 'vintuna');
        }
        if ($i == 2) {
            $count = esc_html__('Three', 'vintuna');
        }
        if ($i == 3) {
            $count = esc_html__('Four', 'vintuna');
        }

        register_sidebar(array(
            'name' => esc_html__('Footer Widget ', 'vintuna') . $count,
            'id' => 'vintuna-footer-widget-' . $i,
            'description' => esc_html__('Add widgets here.', 'vintuna'),
            'before_widget' => '<div id="%1$s" class="widget theme-widget-default %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<header class="theme-widget-header"><h3 class="widget-title">',
            'after_title' => '</h3><span class="block-title-dash"></span></header>',
        ));

    }

}

add_action('widgets_init', 'vintuna_widgets_init');
require get_template_directory() . '/inc/widgets/widget-base.php';
require get_template_directory() . '/inc/widgets/author.php';
require get_template_directory() . '/inc/widgets/home-page-widget.php';
require get_template_directory() . '/inc/widgets/home-page-carousel-widget.php';
require get_template_directory() . '/inc/widgets/home-page-banner-slider-widget.php';
require get_template_directory() . '/inc/widgets/social-link.php';
require get_template_directory() . '/inc/widgets/featured-category-widget.php';
