<?php
/**
 * Custom functions and operations related to widgets.
 *
 * This file contains functions that manage widget functionality 
 * and customize widget behavior within the Yaatra theme.
 *
 * @package Yaatra
 */

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

if ( ! function_exists( 'yaatra_widgets_init' ) ) :

	/**
	 * Register a widget area for the theme.
	 *
	 * This function sets up a designated area where widgets can 
	 * be added, allowing for customization and dynamic content 
	 * display in the theme.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
	 * @since 1.0.0
	 */
	function yaatra_widgets_init() {

		register_sidebar( array(
			'name'          => esc_html__( 'Header Sidebar', 'yaatra' ),
			'id'            => 'header-sidebar',
			'description'   => esc_html__( 'Add widgets here for header left area.', 'yaatra' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<div class="widget-title-wrap"><h4 class="widget-title">',
			'after_title'   => '</h4></div>',
		) );
		
		register_sidebar( array(
			'name'          => esc_html__( 'Sidebar', 'yaatra' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'yaatra' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<div class="widget-title-wrap"><h4 class="widget-title">',
			'after_title'   => '</h4></div>',
		) );

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

		register_sidebar( array(
			'name'          => esc_html__( 'Footer Sidebar', 'yaatra' ),
			'id'            => 'sidebar-footer',
			'description'   => esc_html__( 'Add widgets here for footer widget area.', 'yaatra' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<div class="widget-title-wrap"><h4 class="widget-title">',
			'after_title'   => '</h4></div>',
		) );
	}

endif;

add_action( 'widgets_init', 'yaatra_widgets_init' );

/*-----------------------------------------------------------------------------------------------------------------------*/

add_action( 'widgets_init', 'yaatra_register_widgets' );

if ( ! function_exists( 'yaatra_register_widgets' ) ) :

	/**
	 * Register various widgets for the theme.
	 *
	 * This function is responsible for registering different 
	 * widget areas and their corresponding widget functionality.
	 *
	 * @since 1.0.1
	 */
	function yaatra_register_widgets() {

		// Author Info
		register_widget( 'Yaatra_Author_Info' );

		// Latest Posts
		register_widget( 'Yaatra_Latest_Posts' );
	}

endif;


/*-----------------------------------------------------------------------------------------------------------------------*/
/**
 * Load necessary files for widget functionality.
 *
 * This function includes the required files for registering 
 * and managing widgets in the theme.
 *
 * @since 1.0.0
 */
require get_template_directory() . '/inc/widgets/cv-widget-fields.php';    // Widget fields
require get_template_directory() . '/inc/widgets/cv-author-info.php';    // Author Info
require get_template_directory() . '/inc/widgets/cv-latest-posts.php';    // Author Info