<?php
function mobile_app_launch_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Mobile_App_Launch_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'mobile_app_launch_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'mobile-app-launch' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section( 'mobile_app_launch_slider_section' , array(
    	'title'      => __( 'Slider Section', 'mobile-app-launch' ),
    	'priority' => 2,
		'panel' => 'mobile_app_launch_frontpage_sections'
	) );

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'mobile_app_launch_slider_arrows' , 
			array(
			'default' => false,
			'sanitize_callback' => 'mobile_app_launch_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'mobile_app_launch_slider_arrows', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'mobile-app-launch' ),
			'section'     => 'mobile_app_launch_slider_section',
			'settings'    => 'mobile_app_launch_slider_arrows',
			'type'        => 'checkbox'
		) 
	);

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

		$wp_customize->add_setting( 'mobile_app_launch_slider_page' . $mobile_app_launch_count, array(
			'default'           => '',
			'sanitize_callback' => 'mobile_app_launch_sanitize_dropdown_pages'
		) );
		$wp_customize->add_control( 'mobile_app_launch_slider_page' . $mobile_app_launch_count, array(
			'label'    => __( 'Select Slide Image Page', 'mobile-app-launch' ),
			'section'  => 'mobile_app_launch_slider_section',
			'type'     => 'dropdown-pages'
		) );
	}

	$wp_customize->add_setting( 'mobile_app_launch_upgrade_page_settings_11101',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Mobile_App_Launch_Control_Upgrade(
		$wp_customize, 'mobile_app_launch_upgrade_page_settings_11101',
			array(
				'priority'      => 200,
				'section'       => 'mobile_app_launch_slider_section',
				'settings'      => 'mobile_app_launch_upgrade_page_settings_11101',
				'label'         => __( 'Mobile App Launch Pro comes with additional features.', 'mobile-app-launch' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'mobile-app-launch' ), __( 'One-Click Demo Import', 'mobile-app-launch' ), __( 'WooCommerce Integrated', 'mobile-app-launch' ), __( 'Drag & Drop Section Reordering', 'mobile-app-launch' ),__( 'Advanced Typography Control', 'mobile-app-launch' ),__( 'Intuitive Customization Options', 'mobile-app-launch' ),__( '24/7 Support', 'mobile-app-launch' ), )
			)
		)
	); 

	// About Us Section
	$wp_customize->add_section('mobile_app_launch_about_section', array(
	    'title'    => __('About Us Section', 'mobile-app-launch'),
	    'panel'    => 'mobile_app_launch_frontpage_sections',
	    'priority' => 4,
	));

	$wp_customize->add_setting( 
		'mobile_app_launch_about_enable' , 
			array(
			'default' => true,
			'sanitize_callback' => 'mobile_app_launch_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'mobile_app_launch_about_enable', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'mobile-app-launch' ),
			'section'     => 'mobile_app_launch_about_section',
			'settings'    => 'mobile_app_launch_about_enable',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting('mobile_app_launch_service_sub_heading', array(
	    'default'           => '',
	    'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_app_launch_service_sub_heading', array(
	    'label'    => __('Section Sub Title', 'mobile-app-launch'),
	    'section'  => 'mobile_app_launch_about_section',
	    'type'     => 'text'
	));

	// Add a default "Select" option to the dropdown
	$wp_customize->add_setting('mobile_app_launch_about_page', array(
	    'default'           => get_page_id_by_slug('feature-page'), 
	    'sanitize_callback' => 'mobile_app_launch_sanitize_dropdown_pages'
	));
	$wp_customize->add_control('mobile_app_launch_about_page', array(
	    'label'    => __('Select About Page', 'mobile-app-launch'),
	    'section'  => 'mobile_app_launch_about_section',
	    'type'     => 'dropdown-pages'
	));

	for($mobile_app_launch_i=1;$mobile_app_launch_i<=2;$mobile_app_launch_i++) {

	    $wp_customize->add_setting('mobile_app_launch_tab_heading'.$mobile_app_launch_i,array(
	        'default'=> 'Refreshing to get such a personal touch',
	        'sanitize_callback' => 'sanitize_text_field'
	    ));
	    $wp_customize->add_control('mobile_app_launch_tab_heading'.$mobile_app_launch_i,array(
	        'label' => __('About Title ','mobile-app-launch').$mobile_app_launch_i,
	        'section'=> 'mobile_app_launch_about_section',
	        'setting'=> 'mobile_app_launch_tab_heading'.$mobile_app_launch_i,
	        'type'=> 'text'
	    ));
  	}

  	$wp_customize->add_setting('mobile_app_launch_marketing_percentage', array(
        'default'   => '',
        'sanitize_callback' => 'absint',
    ));

    $wp_customize->add_control('mobile_app_launch_marketing_percentage', array(
        'label'   => __('Add Marketing Percentage', 'mobile-app-launch'),
        'section' => 'mobile_app_launch_about_section',
        'type'    => 'number',
        'input_attrs' => array(
            'min' => 0,
            'max' => 100,
            'step' => 1,
        ),
    ));

    $wp_customize->add_setting('mobile_app_launch_optimization_percentage', array(
        'default'   => '',
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('mobile_app_launch_optimization_percentage', array(
        'label'   => __('Add Optimization Percentage', 'mobile-app-launch'),
        'section' => 'mobile_app_launch_about_section',
        'type'    => 'number',
        'input_attrs' => array(
            'min' => 0,
            'max' => 100,
            'step' => 1,
        ),
    ));

	$wp_customize->add_setting( 'mobile_app_launch_upgrade_page_settings_1110',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Mobile_App_Launch_Control_Upgrade(
		$wp_customize, 'mobile_app_launch_upgrade_page_settings_1110',
			array(
				'priority'      => 200,
				'section'       => 'mobile_app_launch_about_section',
				'settings'      => 'mobile_app_launch_upgrade_page_settings_1110',
				'label'         => __( 'Mobile App Launch Pro comes with additional features.', 'mobile-app-launch' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'mobile-app-launch' ), __( 'One-Click Demo Import', 'mobile-app-launch' ), __( 'WooCommerce Integrated', 'mobile-app-launch' ), __( 'Drag & Drop Section Reordering', 'mobile-app-launch' ),__( 'Advanced Typography Control', 'mobile-app-launch' ),__( 'Intuitive Customization Options', 'mobile-app-launch' ),__( '24/7 Support', 'mobile-app-launch' ), )
			)
		)
	); 

}

add_action( 'customize_register', 'mobile_app_launch_blog_setting' );

// service selective refresh
function mobile_app_launch_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'  => 'mobile_app_launch_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'  => 'mobile_app_launch_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'  => 'mobile_app_launch_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'mobile_app_launch_blog_section_partials' );

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

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

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