<?php

function vegan_cafe_restaurant_footer( $wp_customize ) {
	$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	// Footer Panel // 
	$wp_customize->add_panel( 
		'vegan_cafe_restaurant_footer_section', 
		array(
			'priority'      => 34,
			'capability'    => 'edit_theme_options',
			'title'			=> __('Footer Options', 'vegan-cafe-restaurant'),
		) 
	);

	// Footer Widgets // 
	$wp_customize->add_section(
        'vegan_cafe_restaurant_footer_top',
        array(
            'title' 		=> __('Footer Widgets','vegan-cafe-restaurant'),
			'panel'  		=> 'vegan_cafe_restaurant_footer_section',
			'priority'      => 3,
		)
    );

    // Footer Widgets Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'vegan_cafe_restaurant_footer_widgets_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'vegan_cafe_restaurant_footer_widgets_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Footer Widgets', 'vegan-cafe-restaurant' ),
			'section'     => 'vegan_cafe_restaurant_footer_top',
			'settings'    => 'vegan_cafe_restaurant_footer_widgets_setting',
			'type'        => 'checkbox'
		) 
	);

	// Footer Background Image Setting
	$wp_customize->add_setting('vegan_cafe_restaurant_footer_bg_image',array(
		'default'	=> '',
		'sanitize_callback'	=> 'esc_url_raw',
	));
	$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'vegan_cafe_restaurant_footer_bg_image',array(
		'label' => __('Footer Background Image','vegan-cafe-restaurant'),
		'section' => 'vegan_cafe_restaurant_footer_top'
	)));

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

	$wp_customize->add_control('vegan_cafe_restaurant_footer_bg_image_opacity', array(
		'label'    => __('Footer Background Image Opacity (%)', 'vegan-cafe-restaurant'),
		'section'  => 'vegan_cafe_restaurant_footer_top',
		'type'     => 'range',
		'input_attrs' => array(
			'min'  => 0,
			'max'  => 100,
			'step' => 1,
		),
	));

	// Footer Background Color Setting
    $wp_customize->add_setting('vegan_cafe_restaurant_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,'vegan_cafe_restaurant_footer_bg_color',array(
		'label' => esc_html__('Footer Background Color', 'vegan-cafe-restaurant'),
		'section' => 'vegan_cafe_restaurant_footer_top', // Adjust section if needed
		'settings' => 'vegan_cafe_restaurant_footer_bg_color',
	)));

	$wp_customize->add_setting( 'vegan_cafe_restaurant_upgrade_page_settings_1',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Vegan_Cafe_Restaurant_Control_Upgrade(
        $wp_customize, 'vegan_cafe_restaurant_upgrade_page_settings_1',
            array(
                'priority'      => 200,
                'section'       => 'vegan_cafe_restaurant_footer_top',
                'settings'      => 'vegan_cafe_restaurant_upgrade_page_settings_1',
                'label'         => __( 'Vegan Cafe Restaurant Pro comes with additional features.', 'vegan-cafe-restaurant' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'vegan-cafe-restaurant' ), __( 'One-Click Demo Import', 'vegan-cafe-restaurant' ), __( 'WooCommerce Integrated', 'vegan-cafe-restaurant' ), __( 'Drag & Drop Section Reordering', 'vegan-cafe-restaurant' ),__( 'Advanced Typography Control', 'vegan-cafe-restaurant' ),__( 'Intuitive Customization Options', 'vegan-cafe-restaurant' ),__( '24/7 Support', 'vegan-cafe-restaurant' ), )
            )
        )
    ); 

	// Footer Bottom // 
	$wp_customize->add_section(
        'vegan_cafe_restaurant_footer_bottom',
        array(
            'title' 		=> __('Footer Bottom','vegan-cafe-restaurant'),
			'panel'  		=> 'vegan_cafe_restaurant_footer_section',
			'priority'      => 3,
		)
    );

	// Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'vegan_cafe_restaurant_footer_copyright_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'vegan_cafe_restaurant_footer_copyright_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Footer Copyright', 'vegan-cafe-restaurant' ),
			'section'     => 'vegan_cafe_restaurant_footer_bottom',
			'settings'    => 'vegan_cafe_restaurant_footer_copyright_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Footer Copyright 
	$wp_customize->add_setting(
    	'vegan_cafe_restaurant_footer_copyright',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 4,
		)
	);

	$wp_customize->add_control( 
		'vegan_cafe_restaurant_footer_copyright',
		array(
		    'label'   		=> __('Edit Copyright Text','vegan-cafe-restaurant'),
		    'section'		=> 'vegan_cafe_restaurant_footer_bottom',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting( 'vegan_cafe_restaurant_copyright_alignment', array(
        'default'   => 'center',
        'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_copyright_position',
    ));

    $wp_customize->add_control( 'vegan_cafe_restaurant_copyright_alignment', array(
        'label'    => __( 'Copyright Position', 'vegan-cafe-restaurant' ),
        'section'  => 'vegan_cafe_restaurant_footer_bottom',
        'settings' => 'vegan_cafe_restaurant_copyright_alignment',
        'type'     => 'radio',
        'choices'  => array(
            'right' => __( 'Right Align', 'vegan-cafe-restaurant' ),
            'left'  => __( 'Left Align', 'vegan-cafe-restaurant' ),
            'center'  => __( 'Center Align', 'vegan-cafe-restaurant' ),
        ),
    ));

	$wp_customize->add_setting( 'vegan_cafe_restaurant_upgrade_page_settings_2',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Vegan_Cafe_Restaurant_Control_Upgrade(
        $wp_customize, 'vegan_cafe_restaurant_upgrade_page_settings_2',
            array(
                'priority'      => 200,
                'section'       => 'vegan_cafe_restaurant_footer_bottom',
                'settings'      => 'vegan_cafe_restaurant_upgrade_page_settings_2',
                'label'         => __( 'Vegan Cafe Restaurant Pro comes with additional features.', 'vegan-cafe-restaurant' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'vegan-cafe-restaurant' ), __( 'One-Click Demo Import', 'vegan-cafe-restaurant' ), __( 'WooCommerce Integrated', 'vegan-cafe-restaurant' ), __( 'Drag & Drop Section Reordering', 'vegan-cafe-restaurant' ),__( 'Advanced Typography Control', 'vegan-cafe-restaurant' ),__( 'Intuitive Customization Options', 'vegan-cafe-restaurant' ),__( '24/7 Support', 'vegan-cafe-restaurant' ), )
            )
        )
    ); 
}
add_action( 'customize_register', 'vegan_cafe_restaurant_footer' );

// Footer selective refresh
function vegan_cafe_restaurant_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'  => 'vegan_cafe_restaurant_footer_copyright_render_callback',
	) );
}
add_action( 'customize_register', 'vegan_cafe_restaurant_footer_partials' );

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