<?php
/**
 * Handles widget areas along with related hooks and functions.
 * 
 * @package Blogbuster
 */

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

add_action( 'widgets_init', 'blogbuster_widgets_init' );

if ( ! function_exists( 'blogbuster_widgets_init' ) ) :

    /**
     * Register widget area.
     *
     * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
     */
    function blogbuster_widgets_init() {
        register_sidebar(
            array(
                'name'          => esc_html__( 'Sidebar', 'blogbuster' ),
                'id'            => 'sidebar-1',
                'description'   => esc_html__( 'Add widgets here.', 'blogbuster' ),
                'before_widget' => '<section id="%1$s" class="widget %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => '<h2 class="widget-title">',
                'after_title'   => '</h2>',
            )
        );

        register_sidebar(
            array(
                'name'          => esc_html__( 'Left Sidebar', 'blogbuster' ),
                'id'            => 'left-sidebar',
                'description'   => esc_html__( 'Add widgets here.', 'blogbuster' ),
                'before_widget' => '<section id="%1$s" class="widget %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => '<h2 class="widget-title">',
                'after_title'   => '</h2>',
            )
        );

        /**
         * Register 4 different footer widget area 
         *
         * @since 1.0.0
         */
        register_sidebars( 4 , array(
            'name'          => esc_html__( 'Footer Column %d', 'blogbuster' ),
            'id'            => 'footer-sidebar',
            'description'   => esc_html__( 'Added widgets are display at Footer Widget Area.', 'blogbuster' ),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget'  => '</section>',
            'before_title'  => '<h4 class="widget-title">',
            'after_title'   => '</h4>',
        ) );

        // register widget MT: Trending Posts
        register_widget( 'Blogbuster_Trending_Posts' );

        // register widget MT: Latest Posts
        register_widget( 'Blogbuster_Latest_Posts' );

        // register widget MT: Author Profile
        register_widget( 'Blogbuster_Author_Profile' );
    }

endif;

require get_template_directory().'/inc/widgets/blogbuster-widgets-helper.php';
require get_template_directory().'/inc/widgets/trending-posts.php';
require get_template_directory().'/inc/widgets/latest-posts.php';
require get_template_directory().'/inc/widgets/author-profile.php';