<?php
function electromix_footer( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	// Footer Panel // 
	$wp_customize->add_panel( 
		'footer_section', 
		array(
			'priority'      => 34,
			'capability'    => 'edit_theme_options',
			'title'			=> __('Footer', 'electromix'),
		) 
	);
		
	/*=========================================
	Footer Background 
	=========================================*/	
	$wp_customize->add_section(
        'footer_background',
        array(
            'title' 		=> __('Footer Background','electromix'),
			'panel'  		=> 'footer_section',
			// 'priority'      => 4,
		)
    );
	
	//  Image // 
    $wp_customize->add_setting( 
    	'footer_bg_img' , 
    	array(
			'default' 			=> esc_url(get_template_directory_uri() .'/assets/images/footer/footer_bg.png'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_url',	
		) 
	);
	
	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize , 'footer_bg_img' ,
		array(
			'label'          => esc_html__( 'Background Image', 'electromix'),
			'section'        => 'footer_background',
		) 
	));
	
	//  Background Color
	$wp_customize->add_setting(
	'footer_bg_clr', 
	array(
		'capability' => 'edit_theme_options',
		'sanitize_callback' => 'sanitize_text_field',
		'default' => '#000000'
    ));
	
	$wp_customize->add_control( 
		new WP_Customize_Color_Control
		($wp_customize, 
			'footer_bg_clr', 
			array(
				'label'      => __( 'Background Color', 'electromix' ),
				'section'    => 'footer_background',
			) 
		) 
	);
	
	if ( class_exists( 'Ecommerce_Comp_Customizer_Range_Control' ) ) {
	$wp_customize->add_setting(
		'footer_clr_opacity',
		array(
			'default' => '80',
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'ecommerce_comp_sanitize_range_value',
			'priority' => 11,
		)
	);
	$wp_customize->add_control( 
	new Ecommerce_Comp_Customizer_Range_Control( $wp_customize, 'footer_clr_opacity', 
		array(
			'label'      => __( 'Opacity', 'electromix' ),
			'section'  => 'footer_background',
			 'media_query'   => false,
				'input_attr'    => array(
					'desktop' => array(
						'min'           => 0,
						'max'           => 100,
						'step'          => 1,
						'default_value' => 80,
					),
				),
		) ) 
	);


// Pro Upgrade
	class  Electromix_footer_bg__section_upgrade extends WP_Customize_Control {
		public function render_content() { 		
		?>
			<a class="customizer_footer_bg_section_premium up-to-pro" style="padding:9px 0; text-align:center;" href="<?php echo electromix_premium_links(); ?>" target="_blank"><?php esc_html_e('Upgrade To Pro For More','electromix'); ?></a>
			
		<?php }
	}
	
	$wp_customize->add_setting( 'footer_bg_upgrade_to_pro', array(
		'capability'			=> 'edit_theme_options',
		'electromix_sanitize_callback'	=> 'wp_filter_nohtml_kses',
		'priority' => 5,
	));
	$wp_customize->add_control(
		new  Electromix_footer_bg__section_upgrade(
		$wp_customize,
		'footer_bg_upgrade_to_pro',
			array(
				'section'				=> 'footer_background',
			)
		)
	);
	}
	/*=========================================
	Footer Middle
	=========================================*/	
if ( class_exists( 'Ecommerce_Comp_Customizer' ) ) {	
	$wp_customize->add_section(
        'footer_middle',
        array(
            'title' 		=> __('Footer Row Second','electromix'),
			'panel'  		=> 'footer_section',
		)
    );
	
	// hide/show
	$wp_customize->add_setting( 
		'hs_footer_middle' , 
			array(
			'default' => '1',
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_checkbox',
			'priority' => 1,
		) 
	);
	
	$wp_customize->add_control(
	'hs_footer_middle', 
		array(
			'label'	      => esc_html__( 'Hide/Show', 'electromix' ),
			'section'     => 'footer_middle',
			'type'        => 'checkbox'
		) 
	);	
	
	// Head
	$wp_customize->add_setting( 
		'middle_footer_head' , 
			array(
			'default' => '1',
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			'priority' => 1,
		) 
	);
	
	$wp_customize->add_control(
	'middle_footer_head', 
		array(
			'label'	      => esc_html__( 'Setting', 'electromix' ),
			'section'     => 'footer_middle',
			'type'        => 'hidden'
		) 
	);	
	
	
	// Title
	$wp_customize->add_setting( 
		'footer_middle_wid_ttl' , 
			array(
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			 // //'transport'         => $selective_refresh,
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'footer_middle_wid_ttl', 
		array(
			'label'	      => esc_html__( 'Left Content Title', 'electromix' ),
			'section'     => 'footer_middle',
			'type'        => 'text'
		) 
	);
	
	/**
	 * Customizer Repeater for add Social Icons
	 */
	$wp_customize->add_setting( 'footer_mid_wid_contents', 
		array(
		 'sanitize_callback' => 'electromix_repeater_sanitize',
		 //'transport'         => $selective_refresh,
		 'default' => foot_mid_wid_imgs()
		)
	);
	
	$wp_customize->add_control( 
		new Electromix_Repeater( $wp_customize, 
			'footer_mid_wid_contents', 
				array(
					'label'   => esc_html__('Partners','electromix'),
					'section' => 'footer_middle',
					'add_field_label'                   => esc_html__( 'Add New Client', 'electromix' ),
					'item_name'                         => esc_html__( 'Client', 'electromix' ),
					'customizer_repeater_image_control' => true,
					'customizer_repeater_link_control' => true,
				) 
			) 
		);
	
	// Upgrade To Pro //	
	class  Electromix_client_section_upgrade extends WP_Customize_Control {
		public function render_content() { 	
			
		?>
			<a class="customizer_client_section_premium up-to-pro" style="padding:9px 0; text-align:center; display: none;" href="<?php echo electromix_premium_links(); ?>" target="_blank"><?php esc_html_e('Upgrade To Pro For More','electromix'); ?></a>
			
		<?php }
	}
	
	$wp_customize->add_setting( 'electromix_client_upgrade_to_pro', array(
		'capability'			=> 'edit_theme_options',
		'electromix_sanitize_callback'	=> 'wp_filter_nohtml_kses',
	));
	$wp_customize->add_control(
		new  Electromix_client_section_upgrade(
		$wp_customize,
		'electromix_client_upgrade_to_pro',
			array(
				'section'				=> 'footer_middle',
			)
		)
	);

	/**
	 * Customizer Repeater for add Footer Info
	 */
	
	$wp_customize->add_setting( 'footer_info_contents', 
		array(
		 'sanitize_callback' => 'electromix_repeater_sanitize',
		 // 'transport'         => $selective_refresh,
		 'default' => electromix_get_info_default()
		)
	);
	
	$wp_customize->add_control( 
		new Electromix_Repeater( $wp_customize, 
			'footer_info_contents', 
				array(
					'label'   => esc_html__('Info Items','electromix'),
					'section' => 'footer_middle',
					'add_field_label'                   => esc_html__( 'Add New Info Box3', 'electromix' ),
					'item_name'                         => esc_html__( 'InfoBox3', 'electromix' ),
					'customizer_repeater_title_control' => true,
					'customizer_repeater_text_control' => true,
					'customizer_repeater_icon_control' => true,
					'customizer_repeater_link_control' => true,
				) 
			) 
		);
		
	// Upgrade To Pro //
	class  Electromix_infobox3_section_upgrade extends WP_Customize_Control {
		public function render_content() { 	
			
		?>
			<a class="customizer_infobox3_section_premium up-to-pro" style="padding:9px 0; text-align:center; display: none;" href="<?php echo electromix_premium_links(); ?>" target="_blank"><?php esc_html_e('Upgrade To Pro For More','electromix'); ?></a>
			
		<?php }
	}
	
	$wp_customize->add_setting( 'electromix_infobox3_upgrade_to_pro', array(
		'capability'			=> 'edit_theme_options',
		'electromix_sanitize_callback'	=> 'wp_filter_nohtml_kses',
	));
	$wp_customize->add_control(
		new  Electromix_infobox3_section_upgrade(
		$wp_customize,
		'electromix_infobox3_upgrade_to_pro',
			array(
				'section'				=> 'footer_middle',
			)
		)
	);
	
	/*=========================================
	Footer Above
	=========================================*/	
	$wp_customize->add_section(
        'footer_above',
        array(
            'title' 		=> __('Footer Row Third','electromix'),
			'panel'  		=> 'footer_section',
		)
    );
	
	// Head
	$wp_customize->add_setting( 
		'above_footer_head' , 
			array(
			'default' => '1',
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			'priority' => 1,
		) 
	);
	
	$wp_customize->add_control(
	'above_footer_head', 
		array(
			'label'	      => esc_html__( 'Setting', 'electromix' ),
			'section'     => 'footer_above',
			'type'        => 'hidden'
		) 
	);	
	
	// hide/show
	$wp_customize->add_setting( 
		'hs_above_footer' , 
			array(
			'default' => '1',
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_checkbox',
			'priority' => 1,
		) 
	);
	
	$wp_customize->add_control(
	'hs_above_footer', 
		array(
			'label'	      => esc_html__( 'Hide/Show', 'electromix' ),
			'section'     => 'footer_above',
			'type'        => 'checkbox'
		) 
	);		
	
	
	//  Content
	$wp_customize->add_setting( 
		'above_footer_content' , 
			array(
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			'priority' => 1,
		) 
	);
	
	$wp_customize->add_control(
	'above_footer_content', 
		array(
			'label'	      => esc_html__( 'Content', 'electromix' ),
			'section'     => 'footer_above',
			'type'        => 'hidden'
		) 
	);	
	
	
	// Title
	$wp_customize->add_setting( 
		'footer_abv_wid_ttl' , 
			array(
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			 // //'transport'         => $selective_refresh,
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'footer_abv_wid_ttl', 
		array(
			'label'	      => esc_html__( 'Left Content Title', 'electromix' ),
			'section'     => 'footer_above',
			'type'        => 'text'
		) 
	);
	
	/**
	 * Customizer Repeater for add Social Icons
	 */
	$wp_customize->add_setting( 'footer_abv_wid_contents', 
		array(
		 'sanitize_callback' => 'electromix_repeater_sanitize',
		 //'transport'         => $selective_refresh,
		 'priority' => 8,
		 'default' => foot_abv_wid_imgs()
		)
	);
	
	$wp_customize->add_control( 
		new Electromix_Repeater( $wp_customize, 
			'footer_abv_wid_contents', 
				array(
					'label'   => esc_html__('Apps','electromix'),
					'section' => 'footer_above',
					'add_field_label'                   => esc_html__( 'Add New Platform', 'electromix' ),
					'item_name'                         => esc_html__( 'Platform', 'electromix' ),
					'customizer_repeater_image_control' => true,
					'customizer_repeater_link_control' => true,
				) 
			) 
		);
	
	// Upgrade To Pro //
	class  Electromix_platform_section_upgrade extends WP_Customize_Control {
		public function render_content() { 	
			
		?>
			<a class="customizer_platform_section_premium up-to-pro" style="padding:9px 0; text-align:center; display: none;" href="<?php echo electromix_premium_links(); ?>" target="_blank"><?php esc_html_e('Upgrade To Pro For More','electromix'); ?></a>
			
		<?php }
	}
	
	$wp_customize->add_setting( 'electromix_platform_upgrade_to_pro', array(
		'capability'			=> 'edit_theme_options',
		'electromix_sanitize_callback'	=> 'wp_filter_nohtml_kses',
	));
	$wp_customize->add_control(
		new  Electromix_platform_section_upgrade(
		$wp_customize,
		'electromix_platform_upgrade_to_pro',
			array(
				'section'				=> 'footer_above',
			)
		)
	);
		
	$wp_customize->add_setting( 
		'footer_abv_wid2_ttl' , 
			array(
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
			 // //'transport'         => $selective_refresh,
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'footer_abv_wid2_ttl', 
		array(
			'label'	      => esc_html__( 'Right Content Title', 'electromix' ),
			'section'     => 'footer_above',
			'type'        => 'text'
		) 
	);
}
	
	/* Copyright Section */
	$wp_customize->add_section(
        'footer_copy_Section',
        array(
            'title' 		=> __('Below Footer','electromix'),
			'panel'  		=> 'footer_section',
			// 'priority'      => 4,
		)
    );
	
	// Copyright
	$electromix_copyright = esc_html__('Copyright &copy; [current_year] [site_title] | Powered by [theme_author]', 'electromix' );
	$wp_customize->add_setting( 
		'footer_copyright' , 
			array(
			'default'	      => $electromix_copyright,
			'capability'     => 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_html',
		) 
	);
	
	$wp_customize->add_control(
	'footer_copyright', 
		array(
			'label'	      => esc_html__( 'Copyright', 'electromix' ),
			'section'     => 'footer_copy_Section',
			'type'        => 'textarea',
			'priority' => 10,
		) 
	);
	
	
	/*=========================================
	Footer Menu
	=========================================*/
	$wp_customize->add_section(
        'footer_menu',
        array(
            'title' 		=> __('Footer Menu','electromix'),
			'panel'  		=> 'footer_section',
			// 'priority'      => 6,
		)
    );
	
	// Menu Head
	$wp_customize->add_setting(
		'footer_menu_head'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_text',
		)
	);

	$wp_customize->add_control(
	'footer_menu_head',
		array(
			'type' => 'hidden',
			'label' => __('Global','electromix'),
			'section' => 'footer_menu',
			'priority'  => 1,
		)
	);
		
	// Hide / Show
	$wp_customize->add_setting(
		'footer_menu_hs'
			,array(
			'default'     	=> '2',
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'electromix_sanitize_checkbox',
		)
	);

	
	$wp_customize->add_control(
	'footer_menu_hs',
		array(
			'type' => 'checkbox',
			'label' => __('Hide / Show Menu','electromix'),
			'section' => 'footer_menu',
			'priority'  => 2,
		)
	);
	
}
add_action( 'customize_register', 'electromix_footer' );
// Footer selective refresh
function electromix_footer_partials( $wp_customize ){	
	
	// footer_copyright
	$wp_customize->selective_refresh->add_partial( 'footer_copyright', array(
		'selector'            => '.footer-bottom-wrapper',
		'settings'            => 'footer_copyright',
		'render_callback'  => 'electromix_footer_copyright_render_callback',
	) );
	
	}
add_action( 'customize_register', 'electromix_footer_partials' );

// footer_copyright
function electromix_footer_copyright_render_callback() {
	return get_theme_mod( 'footer_copyright' );
}