<?php
function chargingstation_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', 'charging-station'),
		) 
	);
	
	// Footer top // 
	$wp_customize->add_section(
        'footer_top',
        array(
            'title' 		=> __('Footer Top','charging-station'),
			'panel'  		=> 'footer_section',
			'priority'      => 3,
		)
    );

	// footer bg color
	$footerbgcolor = esc_html__('#161415', 'charging-station' );
	$wp_customize->add_setting(
    	'footer_bg_color',
    	array(
			'default' => $footerbgcolor,
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 6,
		)
	);	

	$wp_customize->add_control( 
		'footer_bg_color',
		array(
		    'label'   		=> __('Footer BG Color','charging-station'),
		    'section'		=> 'footer_top',
			'type' 			=> 'color',
			'transport'         => $selective_refresh,
		)  
	);

	
	// Footer Bottom // 
	$wp_customize->add_section(
        'footer_bottom',
        array(
            'title' 		=> __('Footer Bottom','charging-station'),
			'panel'  		=> 'footer_section',
			'priority'      => 3,
		)
    );
	
	// Footer Copyright Head
	$wp_customize->add_setting(
		'footer_btm_copy_head'
			,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'chargingstation_sanitize_text',
			'priority'  => 3,
		)
	);

	$wp_customize->add_control(
	'footer_btm_copy_head',
		array(
			'type' => 'hidden',
			'label' => __('Copyright','charging-station'),
			'section' => 'footer_bottom',
		)
	);
	
	// Footer Copyright 
	$chargingstation_foo_copy = esc_html__('Copyright &copy; [current_year] [site_title] | Powered by [theme_author]', 'charging-station' );
	$wp_customize->add_setting(
    	'footer_copyright',
    	array(
			'default' => $chargingstation_foo_copy,
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 4,
		)
	);	

	$wp_customize->add_control( 
		'footer_copyright',
		array(
		    'label'   		=> __('Copyright','charging-station'),
		    'section'		=> 'footer_bottom',
			'type' 			=> 'textarea',
			'transport'         => $selective_refresh,
		)  
	);		 
}
add_action( 'customize_register', 'chargingstation_footer' );
// Footer selective refresh
function chargingstation_footer_partials( $wp_customize ){	
	// footer_copyright
	$wp_customize->selective_refresh->add_partial( 'footer_copyright', array(
		'selector'            => '.copy-right .copyright-text',
		'settings'            => 'footer_copyright',
		'render_callback'  => 'chargingstation_footer_copyright_render_callback',
	) );
	
	}
add_action( 'customize_register', 'chargingstation_footer_partials' );


// copyright_content
function chargingstation_footer_copyright_render_callback() {
	return get_theme_mod( 'footer_copyright' );
}