<?php
/**
 * educrap Theme Customizer
 *
 * @package educrap
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function educrap_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'educrap_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'educrap_customize_partial_blogdescription',
			)
		);
	}
}
add_action( 'customize_register', 'educrap_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function educrap_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function educrap_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function educrap_customize_preview_js() {
	wp_enqueue_script( 'educrap-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '', true );
}
add_action( 'customize_preview_init', 'educrap_customize_preview_js' );

/***
    *** Register Customizer Add Panel Function Code start Here
***/
function educrap_Customizer_Add_Panel_Function( $wp_customize ) {

	// Create Custom Aanel for Home Page.
	$wp_customize->add_panel( 'educrap_Panel_Function', array(
		'theme_supports' => '',
		'title'          => __( ' Educrap Theme Options ', 'educrap' ),
		'priority' => 1,
	) ); 
}
add_action( 'customize_register', 'educrap_Customizer_Add_Panel_Function' );
/***
    *** Register Customizer Add Panel Function Code END Here
***/

/***
    *** Register Customizer Home Banner Section Code start Here
***/
class educrap_Banner_Customizer {

	public static function educrap__Banner_Section( $wp_customize ) {

		// Add Home Banner Section Add Section for home page.
		$wp_customize->add_section( 'educrap_For_Home_Page_Banner_Section' , array(
			'title'    => __(' Home Banner Section ','educrap'),
			'panel'    => 'educrap_Panel_Function',
			'priority' => 1,
		) );

		//  ============================================================
	    //       Home Page Banner Section Image Upload         
	    //  ============================================================
	    $wp_customize->add_setting( 'educrap_Banner_Section_Image_Upload', array( 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
	    )); 
	        	   
	    $wp_customize->add_control( new WP_Customize_Image_Control( 
	    	$wp_customize, 'educrap_Home_Banner_Section_Image_Upload_Id', array(
	        'label'    => ' Banner Image ',
	        'priority' => 1,
	        'section'  => 'educrap_For_Home_Page_Banner_Section',
	        'settings' => 'educrap_Banner_Section_Image_Upload',
	        'button_labels' => array(
	                    // All These labels are optional
	                    'select' => __( 'Select Image', 'educrap' ),
	                    'remove' => __( 'Remove Image', 'educrap' ),
	                    'change' => __( 'Change Image', 'educrap' )
	                    )
	    )));


	    $wp_customize->add_setting( 'educrap_Banner_Section_bg_Image_Upload', array( 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
	    )); 
	        	   
	    $wp_customize->add_control( new WP_Customize_Image_Control( 
	    	$wp_customize, 'educrap_Home_Banner_Section_bg_Image_Upload_Id', array(
	        'label'    => ' Background Image ',
	        'priority' => 1,
	        'section'  => 'educrap_For_Home_Page_Banner_Section',
	        'settings' => 'educrap_Banner_Section_bg_Image_Upload',
	        'button_labels' => array(
	                    // All These labels are optional
	                    'select' => __( 'Select Image', 'educrap' ),
	                    'remove' => __( 'Remove Image', 'educrap' ),
	                    'change' => __( 'Change Image', 'educrap' )
	                    )
	    )));

		//  ============================================================
	    //       Home Page Banner Section Section Title        
	    //  ============================================================
		$wp_customize->add_setting( 'educrap_Banner_Section_Title_Name', array(
			'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			
		) );

		// Add Banner Title Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'educrap_Home_Banner_Section_ID',
			    array(
			        'label'    => __( ' Banner Title ', 'educrap' ),
			        'section'  => 'educrap_For_Home_Page_Banner_Section',
			        'settings' => 'educrap_Banner_Section_Title_Name',
			        'type'     => 'text',
			        'priority' => 2,
			    )
		    )
		);

		//  ============================================================
	    //       Home Page Banner Section Content        
	    //  ============================================================
		$wp_customize->add_setting( 'educrap_Banner_Section_Content_Textarea', array(
			'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			
		) );

		// Add Banner Content Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'educrap_Banner_Section_Main_Content',
			    array(
			        'label'    => __( ' Banner Content ', 'educrap' ),
			        'section'  => 'educrap_For_Home_Page_Banner_Section',
			        'settings' => 'educrap_Banner_Section_Content_Textarea',
			        'type'     => 'textarea',
			        'priority' => 3,
			    )
		    )
		);

		//  ============================================================
	    //       Home Page Banner Section Button Text         
	    //  ============================================================
		$wp_customize->add_setting( 'educrap_Banner_Section_Button_Text', array(
			 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			 
		) );

		// Button Text Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'educrap_Home_Banner_Section_Button_Text',
			    array(
			        'label'    => __( ' Button Text ', 'educrap' ),
			        'section'  => 'educrap_For_Home_Page_Banner_Section',
			        'settings' => 'educrap_Banner_Section_Button_Text',
			        'type'     => 'text',
			        'priority' => 4,
			    )
		    )
		);

		//  ============================================================
	    //       Home Page Banner Section Button Url Path          
	    //  ============================================================
		$wp_customize->add_setting( 'educrap_Banner_Btn_URl_Path', array(
			 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			 
		) );

		// Add Button Url Path Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'educrap_Custom_Button_URl_Path',
			    array(
			        'label'    => __( ' Button Url ', 'educrap' ),
			        'section'  => 'educrap_For_Home_Page_Banner_Section',
			        'settings' => 'educrap_Banner_Btn_URl_Path',
			        'type'     => 'text',
			        'priority' => 5,
			    )
		    )
		);

	    // Sanitize Text Function For Home Banner
		function Home_Banner_Section_Sanitize_Text_Function( $text ) {
		    return sanitize_text_field( $text );
		}
	}
}
add_action( 'customize_register', array('educrap_Banner_Customizer', 'educrap__Banner_Section') );
/***
    *** Register Customizer Home Banner Section Code END Here
***/


/***
    *** Register Customizer Blog Section Code start Here
***/
class educrap_Blog_Customizer {

	public static function educrap_Blog_section( $wp_customize ) {

		// Add Blog Section
		$wp_customize->add_section( 'educrap__for_Blog_section' , array(
			'title'    => __(' Blog Section ','educrap'),
			'panel' => 'educrap_Panel_Function',
		) );

		/*******************************************************************************
		                    Blog Section Title Text Code 
		********************************************************************************/
		$wp_customize->add_setting( 'educrap_Blog_Section_Title', array(
	       'sanitize_callback' => 'educrap_Blog_Section_Page_Sanitize_Text',
		) );

		// Add Blog Section Title Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'educrap_Blog_Section_ID',
			    array(
			        'label'    => __( ' Blog Section Title ', 'educrap' ),
			        'section'  => 'educrap__for_Blog_section',
			        'settings' => 'educrap_Blog_Section_Title',
			        'type'     => 'text',
			        'priority' => 1,
			    )
		    )
		);

		/*******************************************************************************
		                    Blog Section Title Description Code 
		********************************************************************************/
		$wp_customize->add_setting( 'educrap_Blog_Section_Description', array(
	       'sanitize_callback' => 'educrap_Blog_Section_Page_Sanitize_Text',
		) );

		// Add Blog Section Description Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'educrap_Blog_Section_Description_Id',
			    array(
			        'label'    => __( ' Blog Section Description ', 'educrap' ),
			        'section'  => 'educrap__for_Blog_section',
			        'settings' => 'educrap_Blog_Section_Description',
			        'type'     => 'textarea',
			        'priority' => 2,
			    )
		    )
		);

	    // Sanitize Text Function For Home Blog  Section
		function educrap_Blog_Section_Page_Sanitize_Text( $text ) {
		    return sanitize_text_field( $text );
		}	
	}
}
add_action( 'customize_register', array('educrap_Blog_Customizer', 'educrap_Blog_section') );
/***
    *** Register Customizer Blog Section Code End Here
***/

/***
    *** Register Customizer Testimonials Section Code start Here
***/
class educrap_Testimonials_Customizer {

    public static function educrap_testimonials_section( $wp_customize ) {

        $wp_customize->add_section( 'educrap__for_testimonials_section', array(
            'title'    => __( ' Testimonials Section ', 'educrap' ),
            'panel'    => 'educrap_Panel_Function',
            'priority' => 3,
        ) );

        $wp_customize->add_setting( 'educrap_Testimonials_Section_Title', array(
            'sanitize_callback' => 'sanitize_text_field',
            'default'           => __( 'What Our Students Say', 'educrap' ),
        ) );
        $wp_customize->add_control( new WP_Customize_Control(
            $wp_customize,
            'educrap_Testimonials_Section_Title_ID',
            array(
                'label'    => __( ' Section Title ', 'educrap' ),
                'section'  => 'educrap__for_testimonials_section',
                'settings' => 'educrap_Testimonials_Section_Title',
                'type'     => 'text',
            )
        ) );

        $wp_customize->add_setting( 'educrap_Testimonials_Section_Description', array(
            'sanitize_callback' => 'sanitize_text_field',
            'default'           => __( 'Real feedback from students and parents who trust Educrap for a better learning journey.', 'educrap' ),
        ) );
        $wp_customize->add_control( new WP_Customize_Control(
            $wp_customize,
            'educrap_Testimonials_Section_Description_ID',
            array(
                'label'    => __( ' Section Description ', 'educrap' ),
                'section'  => 'educrap__for_testimonials_section',
                'settings' => 'educrap_Testimonials_Section_Description',
                'type'     => 'textarea',
            )
        ) );

        $testimonial_fields = array(
            '1' => array( 'name' => 'educrap_Testimonial_1_Name', 'label' => 'Testimonial 1 Name', 'default' => 'Aarav Sharma' ),
            '2' => array( 'name' => 'educrap_Testimonial_2_Name', 'label' => 'Testimonial 2 Name', 'default' => 'Meera Patel' ),
            '3' => array( 'name' => 'educrap_Testimonial_3_Name', 'label' => 'Testimonial 3 Name', 'default' => 'Rohan Verma' ),
        );

        foreach ( $testimonial_fields as $key => $field ) {
            $wp_customize->add_setting( $field['name'], array(
                'sanitize_callback' => 'sanitize_text_field',
                'default'           => $field['default'],
            ) );
            $wp_customize->add_control( new WP_Customize_Control(
                $wp_customize,
                $field['name'] . '_ID',
                array(
                    'label'    => __( $field['label'], 'educrap' ),
                    'section'  => 'educrap__for_testimonials_section',
                    'settings' => $field['name'],
                    'type'     => 'text',
                )
            ) );

            $quote_setting = 'educrap_Testimonial_' . $key . '_Quote';
            $quote_label   = 'Testimonial ' . $key . ' Quote';
            $wp_customize->add_setting( $quote_setting, array(
                'sanitize_callback' => 'sanitize_text_field',
                'default'           => __( 'Great experience with Educrap.', 'educrap' ),
            ) );
            $wp_customize->add_control( new WP_Customize_Control(
                $wp_customize,
                $quote_setting . '_ID',
                array(
                    'label'    => __( $quote_label, 'educrap' ),
                    'section'  => 'educrap__for_testimonials_section',
                    'settings' => $quote_setting,
                    'type'     => 'textarea',
                )
            ) );

            $role_setting = 'educrap_Testimonial_' . $key . '_Role';
            $role_label   = 'Testimonial ' . $key . ' Role';
            $wp_customize->add_setting( $role_setting, array(
                'sanitize_callback' => 'sanitize_text_field',
                'default'           => __( 'Student', 'educrap' ),
            ) );
            $wp_customize->add_control( new WP_Customize_Control(
                $wp_customize,
                $role_setting . '_ID',
                array(
                    'label'    => __( $role_label, 'educrap' ),
                    'section'  => 'educrap__for_testimonials_section',
                    'settings' => $role_setting,
                    'type'     => 'text',
                )
            ) );

            $image_setting = 'educrap_Testimonial_' . $key . '_Image';
            $image_label   = 'Testimonial ' . $key . ' Image';
            $wp_customize->add_setting( $image_setting, array(
                'sanitize_callback' => 'esc_url_raw',
            ) );
            $wp_customize->add_control( new WP_Customize_Image_Control(
                $wp_customize,
                $image_setting . '_ID',
                array(
                    'label'    => __( $image_label, 'educrap' ),
                    'section'  => 'educrap__for_testimonials_section',
                    'settings' => $image_setting,
                )
            ) );
        }
    }
}
add_action( 'customize_register', array( 'educrap_Testimonials_Customizer', 'educrap_testimonials_section' ) );
/***
    *** Register Customizer Testimonials Section Code End Here
***/

/***
	*** Register Customizer Footer Section Code start Here
***/
class educrap_Footer_Customizer {

	public static function educrap_Footer_section( $wp_customize ) {

		// Add Footer Section
		$wp_customize->add_section( 'educrap__for_Footer_section' , array(
			'title'    => __(' Footer Section ','educrap'),
			'panel'    => 'educrap_Panel_Function',
		) );

		/*******************************************************************************
		                    Footer Copyright Text Code 
		********************************************************************************/
		$wp_customize->add_setting( 'educrap_Footer_Copyright', array(
			'default'           => __( '© 2022 Educrap. All Rights Reserved. <a href="https://weblizar.com/">Weblizar</a>', 'educrap' ),
			'sanitize_callback' => 'wp_kses_post',
		) );

		// Add Footer Copyright Control
		$wp_customize->add_control( new WP_Customize_Control(
			$wp_customize,
			'educrap_Footer_Copyright_ID',
			array(
				'label'    => __( ' Footer Copyright Text ', 'educrap' ),
				'section'  => 'educrap__for_Footer_section',
				'settings' => 'educrap_Footer_Copyright',
				'type'     => 'textarea',
				'priority' => 1,
			)
		) );

		// -------------------------------
        // Selective Refresh
        // -------------------------------
        if ( isset( $wp_customize->selective_refresh ) ) {
            $wp_customize->selective_refresh->add_partial( 'educrap_Footer_Copyright', array(
                'selector' => '.copyright-section p',
            ) );
        }
	}
}
add_action( 'customize_register', array('educrap_Footer_Customizer', 'educrap_Footer_section') );