<?php

function mobile_app_launch_footer( $wp_customize ) {
	$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	// Footer Panel // 
	$wp_customize->add_panel( 
		'mobile_app_launch_footer_section', 
		array(
			'priority'      => 34,
			'capability'    => 'edit_theme_options',
			'title'			=> __('Footer Options', 'mobile-app-launch'),
		) 
	);

	// Footer Widgets // 
	$wp_customize->add_section(
        'mobile_app_launch_footer_top',
        array(
            'title' 		=> __('Footer Widgets','mobile-app-launch'),
			'panel'  		=> 'mobile_app_launch_footer_section',
			'priority'      => 3,
		)
    );

    // Footer Widgets Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'mobile_app_launch_footer_widgets_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'mobile_app_launch_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'mobile_app_launch_footer_widgets_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Footer Widgets', 'mobile-app-launch' ),
			'section'     => 'mobile_app_launch_footer_top',
			'settings'    => 'mobile_app_launch_footer_widgets_setting',
			'type'        => 'checkbox'
		) 
	);

	// Footer Background Image Setting
	$wp_customize->add_setting('mobile_app_launch_footer_bg_image',array(
		'default'	=> '',
		'sanitize_callback'	=> 'esc_url_raw',
	));
	$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'mobile_app_launch_footer_bg_image',array(
		'label' => __('Footer Background Image','mobile-app-launch'),
		'section' => 'mobile_app_launch_footer_top'
	)));

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

	$wp_customize->add_control('mobile_app_launch_footer_bg_image_opacity', array(
		'label'    => __('Footer Background Image Opacity (%)', 'mobile-app-launch'),
		'section'  => 'mobile_app_launch_footer_top',
		'type'     => 'range',
		'input_attrs' => array(
			'min'  => 0,
			'max'  => 100,
			'step' => 1,
		),
	));

	// Footer Background Color Setting
    $wp_customize->add_setting('mobile_app_launch_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,'mobile_app_launch_footer_bg_color',array(
		'label' => esc_html__('Footer Background Color', 'mobile-app-launch'),
		'section' => 'mobile_app_launch_footer_top', // Adjust section if needed
		'settings' => 'mobile_app_launch_footer_bg_color',
	)));

	$wp_customize->add_setting( 'mobile_app_launch_upgrade_page_settings_1',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Mobile_App_Launch_Control_Upgrade(
        $wp_customize, 'mobile_app_launch_upgrade_page_settings_1',
            array(
                'priority'      => 200,
                'section'       => 'mobile_app_launch_footer_top',
                'settings'      => 'mobile_app_launch_upgrade_page_settings_1',
                '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' ), )
            )
        )
    ); 

	// Footer Bottom // 
	$wp_customize->add_section(
        'mobile_app_launch_footer_bottom',
        array(
            'title' 		=> __('Footer Bottom','mobile-app-launch'),
			'panel'  		=> 'mobile_app_launch_footer_section',
			'priority'      => 3,
		)
    );
	
	// Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'mobile_app_launch_footer_copyright_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'mobile_app_launch_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'mobile_app_launch_footer_copyright_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Footer Copyright', 'mobile-app-launch' ),
			'section'     => 'mobile_app_launch_footer_bottom',
			'settings'    => 'mobile_app_launch_footer_copyright_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Footer Copyright 
	$wp_customize->add_setting(
    	'mobile_app_launch_footer_copyright',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 4,
		)
	);

	$wp_customize->add_control( 
		'mobile_app_launch_footer_copyright',
		array(
		    'label'   		=> __('Edit Copyright Text','mobile-app-launch'),
		    'section'		=> 'mobile_app_launch_footer_bottom',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting( 'mobile_app_launch_footer_copyright_text_color', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mobile_app_launch_footer_copyright_text_color', array(
			'label'     => __('Change Footer Copyright Text Color', 'mobile-app-launch'),
	    'section' => 'mobile_app_launch_footer_bottom',
	    'settings' => 'mobile_app_launch_footer_copyright_text_color',
  	)));

	$wp_customize->add_setting( 'mobile_app_launch_copyright_alignment', array(
        'default'   => 'center',
        'sanitize_callback' => 'mobile_app_launch_sanitize_copyright_position',
    ));

    $wp_customize->add_control( 'mobile_app_launch_copyright_alignment', array(
        'label'    => __( 'Copyright Position', 'mobile-app-launch' ),
        'section'  => 'mobile_app_launch_footer_bottom',
        'settings' => 'mobile_app_launch_copyright_alignment',
        'type'     => 'radio',
        'choices'  => array(
            'right' => __( 'Right Align', 'mobile-app-launch' ),
            'left'  => __( 'Left Align', 'mobile-app-launch' ),
            'center'  => __( 'Center Align', 'mobile-app-launch' ),
        ),
    ));

    //footer widget title font size
	$wp_customize->add_setting('mobile_app_launch_footer_bottom_copyright_text_font_size',array(
		'default'	=> '',
		'sanitize_callback'	=> 'mobile_app_launch_sanitize_number_absint'
	));
	$wp_customize->add_control('mobile_app_launch_footer_bottom_copyright_text_font_size',array(
		'label'	=> __('Change Footer Copyright Text Font Size in PX','mobile-app-launch'),
		'section'	=> 'mobile_app_launch_footer_bottom',
	    'setting'	=> 'mobile_app_launch_footer_bottom_copyright_text_font_size',
		'type'	=> 'number',
		'input_attrs' => array(
			'step'             => 1,
			'min'              => 0,
			'max'              => 50,
		),
	)); 
	
	$wp_customize->add_setting('mobile_app_launch_footer_bottom_copyright_text_top_bottom_padding',array(
			'default'	=> '',
			'sanitize_callback'	=> 'mobile_app_launch_sanitize_number_absint'
	));
	$wp_customize->add_control('mobile_app_launch_footer_bottom_copyright_text_top_bottom_padding',array(
		'label'	=> __('Change Footer Copyright Top Bottom Spacing in PX','mobile-app-launch'),
		'section'	=> 'mobile_app_launch_footer_bottom',
	    'setting'	=> 'mobile_app_launch_footer_bottom_copyright_text_top_bottom_padding',
		'type'	=> 'number',
		'input_attrs' => array(
			'step'             => 1,
			'min'              => 0,
			'max'              => 50,
		),
	));

	$wp_customize->add_setting( 'mobile_app_launch_upgrade_page_settings_2',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Mobile_App_Launch_Control_Upgrade(
        $wp_customize, 'mobile_app_launch_upgrade_page_settings_2',
            array(
                'priority'      => 200,
                'section'       => 'mobile_app_launch_footer_bottom',
                'settings'      => 'mobile_app_launch_upgrade_page_settings_2',
                '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_footer' );

// Footer selective refresh
function mobile_app_launch_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'  => 'mobile_app_launch_footer_copyright_render_callback',
	) );
}
add_action( 'customize_register', 'mobile_app_launch_footer_partials' );

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