<?php
/**
 * Handle the wigets files and hooks
 * 
 * @package One Newspaper
 * @since 1.0.0
 */

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

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

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

	// header ads banner sidebar
	register_sidebar(
		array(
			'name'          => esc_html__( 'Ads Banner Sidebar', 'one-newspaper' ),
			'id'            => 'ads-banner-sidebar',
			'description'   => esc_html__( 'Add widgets suitable for displaying ads here.', 'one-newspaper' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title one-newspaper-block-title">',
			'after_title'   => '</h2>',
		)
	);

	// front right sidebar
	register_sidebar(
		array(
			'name'          => esc_html__( 'Frontpage - Middle Right Sidebar', 'one-newspaper' ),
			'id'            => 'front-right-sidebar',
			'description'   => esc_html__( 'Add widgets suitable for middle right here.', 'one-newspaper' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title one-newspaper-block-title"><span>',
			'after_title'   => '</span></h2>',
		)
	);

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

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

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

	// footer sidebar - column 3
	register_sidebar(
		array(
			'name'          => esc_html__( 'Footer Sidebar - Column 3', 'one-newspaper' ),
			'id'            => 'footer-sidebar--column-3',
			'description'   => esc_html__( 'Add widgets here.', 'one-newspaper' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title one-newspaper-block-title"><span>',
			'after_title'   => '</span></h2>',
		)
	);

	// footer sidebar - column 4
	register_sidebar(
		array(
			'name'          => esc_html__( 'Footer Sidebar - Column 4', 'one-newspaper' ),
			'id'            => 'footer-sidebar--column-4',
			'description'   => esc_html__( 'Add widgets here.', 'one-newspaper' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title one-newspaper-block-title"><span>',
			'after_title'   => '</span></h2>',
		)
	);

	// Header Widget Area
	register_sidebar(
		array(
			'name'          => esc_html__( 'Header Builder Widget Area', 'one-newspaper' ),
			'id'            => 'header-builder-widget-area',
			'description'   => esc_html__( 'Add widgets here.', 'one-newspaper' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title one-newspaper-block-title"><span>',
			'after_title'   => '</span></h2>',
		)
	);

	// Register custom widgets
    register_widget( 'One_Newspaper_Widget_Title_Widget' ); // custom widget title
	register_widget( 'One_Newspaper_Posts_List_Widget' ); // post lists widget
	register_widget( 'One_Newspaper_Posts_Grid_Widget' ); // post grid widget
	register_widget( 'One_Newspaper_Category_Collection_Widget' ); // category collection widget
	register_widget( 'One_Newspaper_Author_Info_Widget' ); // author info widget
	register_widget( 'One_Newspaper_Banner_Ads_Widget' ); // banner ad widget
	register_widget( 'One_Newspaper_Popular_Posts_Widget' ); // popular posts widget
	register_widget( 'One_Newspaper_Tabbed_Posts_Widget' ); // tabbed posts widget
	register_widget( 'One_Newspaper_Carousel_Widget' ); // carousel widget
	register_widget( 'One_Newspaper_Social_Icons_Widget' ); // social icons widget
	register_widget( 'One_Newspaper_Posts_Grid_Two_Column_Widget' ); // post grid two column widget
	register_widget( 'One_Newspaper_News_Filter_Tabbed_Widget' ); // post news filter tabbed widget
	register_widget( 'One_Newspaper_Ads_Slider_Widget' ); // ads slider widget
}
add_action( 'widgets_init', 'one_newspaper_widgets_init' );

// includes files
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/widget-fields.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/category-collection.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/posts-list.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/posts-grid.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/author-info.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/banner-ads.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/popular-posts.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/tabbed-posts.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/carousel.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/social-icons.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/widget-title.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/posts-grid-two-column.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/news-filter-tabbed.php';
require ONE_NEWSPAPER_INCLUDES_PATH .'widgets/banner-ads-slider.php';

function one_newspaper_widget_scripts($hook) {
    if( $hook !== "widgets.php" ) {
        return;
    }
    wp_enqueue_style( 'one-newspaper-widget', get_template_directory_uri() . '/inc/widgets/assets/widgets.css', array(), ONE_NEWSPAPER_VERSION );
	wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/assets/lib/fontawesome/css/all.min.css', array(), '6.4.2', 'all' );
	wp_enqueue_media();
	wp_enqueue_script( 'one-newspaper-widget', get_template_directory_uri() . '/inc/widgets/assets/widgets.js', array( 'jquery' ), ONE_NEWSPAPER_VERSION, true );
}
add_action( 'admin_enqueue_scripts', 'one_newspaper_widget_scripts' );

if( ! function_exists( 'one_newspaper_get_tabbed_icon_classes' ) ) :
	/**
	 * List of icons classes
	 * 
	 * @package One Newspaper
	 */
	function one_newspaper_get_tabbed_icon_classes() {
		return apply_filters( 'one_newspaper_tabbed_block_icons', array( "fas fa-ban","fas fa-clock","far fa-clock","fas fa-newspaper","far fa-newspaper","fas fa-poll","fas fa-poll-h","fas fa-ban","fas fa-fire","fas fa-fire-alt","fas fa-comments","fas fa-comment-dots","far fa-comment-dots","far fa-comment","far fa-comments","fas fa-comment-alt","far fa-comment-alt" ) );
	}
endif;