<?php

function expert_gamer_footer( $wp_customize ) {
	$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	// Footer Panel // 
	$wp_customize->add_panel( 
		'expert_gamer_footer_section', 
		array(
			'priority'      => 34,
			'capability'    => 'edit_theme_options',
			'title'			=> __('Footer Options', 'expert-gamer'),
		) 
	);

	// Footer Widgets // 
	$wp_customize->add_section(
        'expert_gamer_footer_top',
        array(
            'title' 		=> __('Footer Widgets','expert-gamer'),
			'panel'  		=> 'expert_gamer_footer_section',
			'priority'      => 3,
		)
    );

    // Footer Widgets Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_gamer_footer_widgets_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_gamer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'expert_gamer_footer_widgets_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Footer Widgets', 'expert-gamer' ),
			'section'     => 'expert_gamer_footer_top',
			'settings'    => 'expert_gamer_footer_widgets_setting',
			'type'        => 'checkbox'
		) 
	);

	// Footer Background Image Setting
	$wp_customize->add_setting('expert_gamer_footer_bg_image',array(
		'default'	=> '',
		'sanitize_callback'	=> 'esc_url_raw',
	));
	$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'expert_gamer_footer_bg_image',array(
	'label' => __('Footer Background Image','expert-gamer'),
	'section' => 'expert_gamer_footer_top'
	)));

	// Footer Background Image Opacity
	$wp_customize->add_setting('expert_gamer_footer_bg_image_opacity', array(
		'default'           => 50,
		'sanitize_callback' => 'absint',
		'capability'        => 'edit_theme_options',
	));

	$wp_customize->add_control('expert_gamer_footer_bg_image_opacity', array(
		'label'    => __('Footer Background Image Opacity (%)', 'expert-gamer'),
		'section'  => 'expert_gamer_footer_top',
		'type'     => 'range',
		'input_attrs' => array(
			'min'  => 0,
			'max'  => 100,
			'step' => 1,
		),
	));

	// Footer Background Color Setting
    $wp_customize->add_setting('expert_gamer_footer_bg_color',array(
		'default' => '#000000',
		'sanitize_callback' => 'sanitize_hex_color',
		'capability' => 'edit_theme_options',
	));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,'expert_gamer_footer_bg_color',array(
		'label' => esc_html__('Footer Background Color', 'expert-gamer'),
		'section' => 'expert_gamer_footer_top', // Adjust section if needed
		'settings' => 'expert_gamer_footer_bg_color',
	)));

	$wp_customize->add_setting( 'expert_gamer_upgrade_page_settings_1',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Expert_Gamer_Control_Upgrade(
        $wp_customize, 'expert_gamer_upgrade_page_settings_1',
            array(
                'priority'      => 200,
                'section'       => 'expert_gamer_footer_top',
                'settings'      => 'expert_gamer_upgrade_page_settings_1',
                'label'         => __( 'Expert Gamer Pro comes with additional features.', 'expert-gamer' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'expert-gamer' ), __( 'One-Click Demo Import', 'expert-gamer' ), __( 'WooCommerce Integrated', 'expert-gamer' ), __( 'Drag & Drop Section Reordering', 'expert-gamer' ),__( 'Advanced Typography Control', 'expert-gamer' ),__( 'Intuitive Customization Options', 'expert-gamer' ),__( '24/7 Support', 'expert-gamer' ), )
            )
        )
    ); 

	// Footer Bottom // 
	$wp_customize->add_section(
        'expert_gamer_footer_bottom',
        array(
            'title' 		=> __('Footer Bottom','expert-gamer'),
			'panel'  		=> 'expert_gamer_footer_section',
			'priority'      => 3,
		)
    );

	// Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_gamer_footer_copyright_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_gamer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'expert_gamer_footer_copyright_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Footer Copyright', 'expert-gamer' ),
			'section'     => 'expert_gamer_footer_bottom',
			'settings'    => 'expert_gamer_footer_copyright_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Footer Copyright 
	// $expert_gamer_foo_copy = esc_html__('Copyright &copy; 2023, Expert Gamer WordPress Theme', 'expert-gamer' );
	$wp_customize->add_setting(
    	'expert_gamer_footer_copyright',
    	array(
			// 'default' => $expert_gamer_foo_copy,
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 4,
		)
	);

	$wp_customize->add_control( 
		'expert_gamer_footer_copyright',
		array(
		    'label'   		=> __('Edit Copyright Text','expert-gamer'),
		    'section'		=> 'expert_gamer_footer_bottom',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting( 'expert_gamer_footer_copyright_text_color', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'expert_gamer_footer_copyright_text_color', array(
			'label'     => __('Change Footer Copyright Text Color', 'expert-gamer'),
	    'section' => 'expert_gamer_footer_bottom',
	    'settings' => 'expert_gamer_footer_copyright_text_color',
  	)));

	$wp_customize->add_setting( 'expert_gamer_copyright_alignment', array(
        'default'   => 'center',
        'sanitize_callback' => 'expert_gamer_sanitize_copyright_position',
    ));

    $wp_customize->add_control( 'expert_gamer_copyright_alignment', array(
        'label'    => __( 'Copyright Position', 'expert-gamer' ),
        'section'  => 'expert_gamer_footer_bottom',
        'settings' => 'expert_gamer_copyright_alignment',
        'type'     => 'radio',
        'choices'  => array(
            'right' => __( 'Right Align', 'expert-gamer' ),
            'left'  => __( 'Left Align', 'expert-gamer' ),
            'center'  => __( 'Center Align', 'expert-gamer' ),
        ),
    ));

	$wp_customize->add_setting( 'expert_gamer_upgrade_page_settings_2',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Expert_Gamer_Control_Upgrade(
        $wp_customize, 'expert_gamer_upgrade_page_settings_2',
            array(
                'priority'      => 200,
                'section'       => 'expert_gamer_footer_bottom',
                'settings'      => 'expert_gamer_upgrade_page_settings_2',
                'label'         => __( 'Expert Gamer Pro comes with additional features.', 'expert-gamer' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'expert-gamer' ), __( 'One-Click Demo Import', 'expert-gamer' ), __( 'WooCommerce Integrated', 'expert-gamer' ), __( 'Drag & Drop Section Reordering', 'expert-gamer' ),__( 'Advanced Typography Control', 'expert-gamer' ),__( 'Intuitive Customization Options', 'expert-gamer' ),__( '24/7 Support', 'expert-gamer' ), )
            )
        )
    ); 
}
add_action( 'customize_register', 'expert_gamer_footer' );

// Footer selective refresh
function expert_gamer_footer_partials( $wp_customize ){
	// footer_copyright
	$wp_customize->selective_refresh->add_partial( 'expert_gamer_footer_copyright', array(
		'selector'            => '.copy-right .copyright-text',
		'settings'            => 'expert_gamer_footer_copyright',
		'render_callback'  => 'expert_gamer_footer_copyright_render_callback',
	) );
}
add_action( 'customize_register', 'expert_gamer_footer_partials' );

// copyright_content
function expert_gamer_footer_copyright_render_callback() {
	return get_theme_mod( 'expert_gamer_footer_copyright' );
}