<?php
/**
 * File to handle widget area and related hooks and functions.
 * 
 * @package PureNote
 */

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

add_action( 'widgets_init', 'purenote_widgets_init' );

if ( ! function_exists( 'purenote_widgets_init' ) ) :

	/**
	 * Register widget areas.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
	 */
	function purenote_widgets_init() {

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

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

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

		// Register custom widgets
		register_widget( 'purenote_Latest_Posts' );
		register_widget( 'purenote_Trending_Posts' );
		register_widget( 'purenote_Author_Profile' );
	}

endif;

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