<?php
/**
 * Register widget area.
 */
if(!function_exists('trainify_homepage_widget_layout')):

    function trainify_homepage_widget_layout(){

        $layout = get_theme_mod( 'homepage_widget_layout', 'layout2' );
        if($layout == 'layout1' ){
            $html_layout = '<h2 class="tff-block-title"><span class="title-wrapper">';
        }else{
            $html_layout = '<h2 class="section-title"><span class="title-wrapper">';
        }
        return $html_layout;

    }

endif;

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
if(!function_exists('trainify_register_sidebar') ):

    function trainify_register_sidebar() {

        $widget_layout = get_theme_mod( 'homepage_widget_layout', 'layout2' );

        /**
         * Register right sidebar
         *
         * @since 1.0.0
         */
        register_sidebar( 
            array(
                'name'          => esc_html__( 'Right Sidebar', 'trainify' ),
                'id'            => 'trainify_right_sidebar',
                'description'   => esc_html__( 'Add widgets here.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => '<h4 class="widget-title"><span class="title-wrapper">',
                'after_title'   => '</span></h4>',
            )
        );

        /**
         * Register left sidebar
         *
         * @since 1.0.0
         */
        register_sidebar(
            array(
                'name'          => esc_html__( 'Left Sidebar', 'trainify' ),
                'id'            => 'trainify_left_sidebar',
                'description'   => esc_html__( 'Add widgets here.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => '<h4 class="widget-title"><span class="title-wrapper">',
                'after_title'   => '</span></h4>',
            )
        );

        /**
         * Header widget area
         *
         * @since 1.0.0
         */
        register_sidebar(
            array(
                'name'          => esc_html__( 'Header Branding Area', 'trainify' ),
                'id'            => 'trainify_header_branding_area',
                'description'   => esc_html__( 'Add widgets here to display header branding section.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => '<h4 class="widget-title"><span class="title-wrapper">',
                'after_title'   => '</span></h4>',
            )
        );

        /**
         * Register home Content area
         *
         * @since 1.0.0
         */
        register_sidebar( 
            array(
                'name'          => esc_html__( 'Top Home Area (Full Width)', 'trainify' ),
                'id'            => 'trainify_home_content_area',
                'description'   => esc_html__( 'Add widgets here.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget widget-'.$widget_layout.' %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => trainify_homepage_widget_layout(),
                'after_title'   => '</span></h2>',
            ) 
        );

        /**
         * Register home middle section area
         *
         * @since 1.0.0
         */
        register_sidebar( 
            array(
                'name'          => esc_html__( 'Home Left Area( Middle Part )', 'trainify' ),
                'id'            => 'trainify_home_middle_section_area',
                'description'   => esc_html__( 'Add widgets here.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget widget-'.$widget_layout.' %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => trainify_homepage_widget_layout(),
                'after_title'   => '</span></h2>',
            ) 
        );

        /**
         * Register home middle aside area
         *
         * @since 1.0.0
         */
        register_sidebar( 
            array(
                'name'          => esc_html__( 'Home Sidebar( Middle part ) ', 'trainify' ),
                'id'            => 'trainify_home_middle_aside_area',
                'description'   => esc_html__( 'Add widgets here.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => '<h4 class="tff-block-title"><span class="title-wrapper">',
                'after_title'   => '</span></h4>',
            ) 
        );

        /**
         * Register home bottom section area
         *
         * @since 1.0.0
         */
        register_sidebar( 
            array(
                'name'          => esc_html__( 'Bottom Home Area', 'trainify' ),
                'id'            => 'trainify_home_bottom_section_area',
                'description'   => esc_html__( 'Add widgets here.', 'trainify' ),
                'before_widget' => '<section id="%1$s" class="widget widget-'.$widget_layout.' %2$s">',
                'after_widget'  => '</section>',
                'before_title'  => trainify_homepage_widget_layout(),
                'after_title'   => '</span></h2>',
            ) 
        );

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

endif;

add_action('widgets_init', 'trainify_register_sidebar');

if(!function_exists('trainify_register_widgets')):

    function trainify_register_widgets(){

        require_once trainify_file_directory('inc/widgets/functions-trainify-widgets.php');
        require_once trainify_file_directory('inc/widgets/class-tff-block-posts-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-call-to-action-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-featured-blocks-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-site-carousel-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-default-tabbed-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-our-team-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-testimonial-section-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-page-block-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-contact-form-widget.php');
        require_once trainify_file_directory('inc/widgets/class-tff-video-block-widget.php');

        register_widget( 'Trainify_Block_Posts_Widget' );
        register_widget( 'Trainify_Call_To_Action_Widget' );
        register_widget( 'Trainify_Featured_Blocks_Widget' );
        register_widget( 'Trainify_Site_Carousel_Widget' );
        register_widget( 'Trainify_Default_Tabbed_Widget' );
        register_widget( 'Trainify_Our_Team_Widget' );
        register_widget( 'Trainify_Testimonial_Section_Widget' );
        register_widget( 'Trainify_Page_Block_Widget' );
        register_widget( 'Trainify_Contact_Form_Widget' );
        register_widget( 'Trainify_Video_Block_Widget' );
        
        if( class_exists('LearnPress') ){
            require_once trainify_file_directory('inc/widgets/class-tff-course-search-widget.php');
            require_once trainify_file_directory('inc/widgets/class-tff-course-listing-widget.php');
            register_widget( 'Trainify_Course_Search_Widget' );
            register_widget( 'Trainify_Course_Listing_Widget' );
        }

    }

endif;

add_action('widgets_init', 'trainify_register_widgets');