<?php
function islamic_trust_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Islamic_Trust_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'islamic_trust_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'islamic-trust' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section( 'islamic_trust_slider_section' , array(
    	'title'      => __( 'Slider Section', 'islamic-trust' ),
    	'priority' => 2,
		'panel' => 'islamic_trust_frontpage_sections'
	) );

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'islamic_trust_slider_arrows' , 
			array(
			'default' => false,
			'sanitize_callback' => 'islamic_trust_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'islamic_trust_slider_arrows', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'islamic-trust' ),
			'section'     => 'islamic_trust_slider_section',
			'settings'    => 'islamic_trust_slider_arrows',
			'type'        => 'checkbox'
		) 
	);

	for ( $islamic_trust_count = 1; $islamic_trust_count <= 4; $islamic_trust_count++ ) {

		$wp_customize->add_setting( 'islamic_trust_slider_page' . $islamic_trust_count, array(
			'default'           => '',
			'sanitize_callback' => 'islamic_trust_sanitize_dropdown_pages'
		) );
		$wp_customize->add_control( 'islamic_trust_slider_page' . $islamic_trust_count, array(
			'label'    => __( 'Select Slide Image Page', 'islamic-trust' ),
			'section'  => 'islamic_trust_slider_section',
			'type'     => 'dropdown-pages'
		) );
	}

	$wp_customize->add_setting('islamic_trust_slider_short_heading',array(
		'default'=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('islamic_trust_slider_short_heading',array(
		'label'	=> __('Add Slider Top Text','islamic-trust'),
		'section'=> 'islamic_trust_slider_section',
		'type'=> 'text'
	));

	$wp_customize->add_setting('islamic_trust_total_yr_completed',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('islamic_trust_total_yr_completed',array(
		'label'	=> __('Add Total Years Completed','islamic-trust'),
		'section'	=> 'islamic_trust_slider_section',
		'type'		=> 'text'
	));

	$wp_customize->add_setting( 'islamic_trust_upgrade_page_settings_1111',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Islamic_Trust_Control_Upgrade(
		$wp_customize, 'islamic_trust_upgrade_page_settings_1111',
			array(
				'priority'      => 200,
				'section'       => 'islamic_trust_slider_section',
				'settings'      => 'islamic_trust_upgrade_page_settings_1111',
				'label'         => __( 'Islamic Trust Pro comes with additional features.', 'islamic-trust' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'islamic-trust' ), __( 'One-Click Demo Import', 'islamic-trust' ), __( 'WooCommerce Integrated', 'islamic-trust' ), __( 'Drag & Drop Section Reordering', 'islamic-trust' ),__( 'Advanced Typography Control', 'islamic-trust' ),__( 'Intuitive Customization Options', 'islamic-trust' ),__( '24/7 Support', 'islamic-trust' ), )
			)
		)
	); 

	// About Us Section
	$wp_customize->add_section('islamic_trust_about_section', array(
	    'title'    => __('About Us Section', 'islamic-trust'),
	    'panel'    => 'islamic_trust_frontpage_sections',
	    'priority' => 4,
	));

	$wp_customize->add_setting( 
		'islamic_trust_about_enable' , 
			array(
			'default' => false,
			'sanitize_callback' => 'islamic_trust_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'islamic_trust_about_enable', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'islamic-trust' ),
			'section'     => 'islamic_trust_about_section',
			'settings'    => 'islamic_trust_about_enable',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting('islamic_trust_about_short_heading', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('islamic_trust_about_short_heading', array(
	    'label' => __('Add Small Title', 'islamic-trust'),
	    'section' => 'islamic_trust_about_section',
	    'type' => 'text',
	));

	$wp_customize->add_setting('islamic_trust_about_page', array(
	    'default' => get_page_id_by_slug('about-page'),
	    'sanitize_callback' => 'islamic_trust_sanitize_dropdown_pages',
	));
	$wp_customize->add_control('islamic_trust_about_page', array(
	    'label' => __('Select About Page', 'islamic-trust'),
	    'section' => 'islamic_trust_about_section',
	    'type' => 'dropdown-pages',
	));

	$wp_customize->add_setting('islamic_trust_abt_image', array(
	    'default' => '',
	    'sanitize_callback' => 'esc_url_raw',
	));
	$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'islamic_trust_abt_image', array(
	    'label' => __('About Image', 'islamic-trust'),
	    'section' => 'islamic_trust_about_section',
	)));

	$wp_customize->add_setting('islamic_trust_total_no_supporters', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('islamic_trust_total_no_supporters', array(
	    'label' => __('Add Total Number of Supporters', 'islamic-trust'),
	    'section' => 'islamic_trust_about_section',
	    'type' => 'text',
	));

	$wp_customize->add_setting('islamic_trust_total_no_amount_raised', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('islamic_trust_total_no_amount_raised', array(
	    'label' => __('Add Total Amount Raised', 'islamic-trust'),
	    'section' => 'islamic_trust_about_section',
	    'type' => 'text',
	));

	$wp_customize->add_setting('islamic_trust_total_year_experience', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('islamic_trust_total_year_experience', array(
	    'label' => __('Add Total Years of Experience', 'islamic-trust'),
	    'section' => 'islamic_trust_about_section',
	    'type' => 'text',
	));

	$wp_customize->add_setting( 'islamic_trust_upgrade_page_settings_101',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Islamic_Trust_Control_Upgrade(
		$wp_customize, 'islamic_trust_upgrade_page_settings_101',
			array(
				'priority'      => 200,
				'section'       => 'islamic_trust_about_section',
				'settings'      => 'islamic_trust_upgrade_page_settings_101',
				'label'         => __( 'Islamic Trust Pro comes with additional features.', 'islamic-trust' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'islamic-trust' ), __( 'One-Click Demo Import', 'islamic-trust' ), __( 'WooCommerce Integrated', 'islamic-trust' ), __( 'Drag & Drop Section Reordering', 'islamic-trust' ),__( 'Advanced Typography Control', 'islamic-trust' ),__( 'Intuitive Customization Options', 'islamic-trust' ),__( '24/7 Support', 'islamic-trust' ), )
			)
		)
	); 

}

add_action( 'customize_register', 'islamic_trust_blog_setting' );

// service selective refresh
function islamic_trust_blog_section_partials( $wp_customize ){	
	// blog_title
	$wp_customize->selective_refresh->add_partial( 'blog_title', array(
		'selector'            => '.home-blog .title h6',
		'settings'            => 'blog_title',
		'render_callback'  => 'islamic_trust_blog_title_render_callback',
	
	) );
	
	// blog_subtitle
	$wp_customize->selective_refresh->add_partial( 'blog_subtitle', array(
		'selector'            => '.home-blog .title h2',
		'settings'            => 'blog_subtitle',
		'render_callback'  => 'islamic_trust_blog_subtitle_render_callback',
	
	) );
	
	// blog_description
	$wp_customize->selective_refresh->add_partial( 'blog_description', array(
		'selector'            => '.home-blog .title p',
		'settings'            => 'blog_description',
		'render_callback'  => 'islamic_trust_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'islamic_trust_blog_section_partials' );

// blog_title
function islamic_trust_blog_title_render_callback() {
	return get_theme_mod( 'blog_title' );
}

// blog_subtitle
function islamic_trust_blog_subtitle_render_callback() {
	return get_theme_mod( 'blog_subtitle' );
}

// service description
function islamic_trust_blog_description_render_callback() {
	return get_theme_mod( 'blog_description' );
}