<?php
/**
 * Sponsor Section options
 *
 * @package Theme Palace
 * @sub_package Raise Charity Pro
 * @since Raise Charity Pro 1.0.0
 */

// Add Sponsor section
$wp_customize->add_section( 'raise_charity_pro_sponsor_section', array(
	'title'             => esc_html__( 'Sponsor','raise-charity-pro' ),
	'description'       => esc_html__( 'Sponsor Section options.', 'raise-charity-pro' ),
	'panel'             => 'raise_charity_pro_front_page_panel',
) );

// Sponsor content enable control and setting
$wp_customize->add_setting( 'raise_charity_pro_theme_options[sponsor_section_enable]', array(
	'default'			=> 	$options['sponsor_section_enable'],
	'sanitize_callback' => 'raise_charity_pro_sanitize_switch_control',
) );

$wp_customize->add_control( new Raise_Charity_Pro_Switch_Control( $wp_customize, 'raise_charity_pro_theme_options[sponsor_section_enable]', array(
	'label'             => esc_html__( 'Sponsor Section Enable', 'raise-charity-pro' ),
	'section'           => 'raise_charity_pro_sponsor_section',
	'on_off_label' 		=> raise_charity_pro_switch_options(),
) ) );

if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'raise_charity_pro_theme_options[sponsor_section_enable]', array(
		'selector'            => '#sponsor-section .tooltiptext',
		'settings'            => 'raise_charity_pro_theme_options[sponsor_section_enable]',
    ) );
}

// sponsor title setting and control
$wp_customize->add_setting( 'raise_charity_pro_theme_options[sponsor_title]',
	array(
		'default'       		=> $options['sponsor_title'],
		'sanitize_callback'		=> 'sanitize_text_field',
		'transport'				=> 'postMessage',
	)
);
$wp_customize->add_control( 'raise_charity_pro_theme_options[sponsor_title]',
    array(
		'label'      			=> esc_html__( 'Section Title', 'raise-charity-pro' ),
		'section'    			=> 'raise_charity_pro_sponsor_section',
		'type'		 			=> 'text',
		'active_callback'		=> 'raise_charity_pro_is_sponsor_section_enable',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'raise_charity_pro_theme_options[sponsor_title]', array(
		'selector'            => '#sponsor-section h2.section-title',
		'settings'            => 'raise_charity_pro_theme_options[sponsor_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'raise_charity_pro_sponsor_title_partial',
    ) );
}

// Gallery btn label setting and control
$wp_customize->add_setting( 'raise_charity_pro_theme_options[sponsor_sub_title]', array(
	'sanitize_callback' => 'wp_kses_post',
	'default'			=> $options['sponsor_sub_title'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'raise_charity_pro_theme_options[sponsor_sub_title]', array(
	'label'           	=> esc_html__( 'Subtitle', 'raise-charity-pro' ),
	'section'        	=> 'raise_charity_pro_sponsor_section',
	'active_callback' 	=> 'raise_charity_pro_is_sponsor_section_enable',
	'type'				=> 'textarea',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'raise_charity_pro_theme_options[sponsor_sub_title]', array(
		'selector'            => '#sponsor-section p.section-subtitle',
		'settings'            => 'raise_charity_pro_theme_options[sponsor_sub_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'raise_charity_pro_sponsor_sub_title_partial',
    ) );
}

// Event social icons number control and setting
$wp_customize->add_setting( 'raise_charity_pro_theme_options[sponsor_count]', array(
	'default'          	=> $options['sponsor_count'],
	'sanitize_callback' => 'raise_charity_pro_sanitize_number_range',
	'validate_callback' => 'raise_charity_pro_validate_sponsor_count',
) );

$wp_customize->add_control( 'raise_charity_pro_theme_options[sponsor_count]', array(
	'label'             => esc_html__( 'Number of Posts', 'raise-charity-pro' ),
	'description'       => esc_html__( 'Note: Min 1 & Max 20. Please input the valid number and save. Then refresh the page to see the change.', 'raise-charity-pro' ),
	'section'           => 'raise_charity_pro_sponsor_section',
	'active_callback'   => 'raise_charity_pro_is_sponsor_section_enable',
	'type'				=> 'number',
	'input_attrs'		=> array(
		'min'	=> 1,
		'max'	=> 20,
		'style' => 'width: 100px;'
		),
) );

for ( $i = 1; $i <= $options['sponsor_count']; $i++ ) :

	// Sponsor image setting and control.
	$wp_customize->add_setting( 'raise_charity_pro_theme_options[sponsor_image_' . $i . ']', array(
		'sanitize_callback' => 'raise_charity_pro_sanitize_image',
	) );

	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'raise_charity_pro_theme_options[sponsor_image_' . $i . ']',
			array(
			'label'       		=> sprintf( esc_html__( 'Image %d', 'raise-charity-pro' ), $i),
			'section'     		=> 'raise_charity_pro_sponsor_section',
			'active_callback'	=> 'raise_charity_pro_is_sponsor_section_enable',
	) ) );

	// Sponsor url setting and control
	$wp_customize->add_setting( 'raise_charity_pro_theme_options[sponsor_url_' . $i . ']', array(
		'sanitize_callback' => 'esc_url_raw',
	) );

	$wp_customize->add_control( 'raise_charity_pro_theme_options[sponsor_url_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Sponsor Url %d', 'raise-charity-pro' ), $i),
		'section'        	=> 'raise_charity_pro_sponsor_section',
		'active_callback' 	=> 'raise_charity_pro_is_sponsor_section_enable',
		'type'				=> 'url',
	) );

endfor;