<?php
/**
 * Sponsor Section options
 *
 * @package Theme Palace
 * @subpackage Charity Give
 * @since Charity Give 1.0.0
 */

// Add Sponsor section
$wp_customize->add_section( 'charity_give_sponsor_section', array(
	'title'             => esc_html__( 'Sponsor','charity-give' ),
	'description'       => esc_html__( 'Sponsor Section options.', 'charity-give' ),
	'panel'             => 'charity_give_front_page_panel',
) );

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

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[sponsor_section_enable]', array(
	'label'             => esc_html__( 'Sponsor Section Enable', 'charity-give' ),
	'section'           => 'charity_give_sponsor_section',
	'on_off_label' 		=> charity_give_switch_options(),
) ) );

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

// Title setting and control
$wp_customize->add_setting( 'charity_give_theme_options[sponsor_title]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default' => $options['sponsor_title'],
	'transport'			=> 'postMessage',
	) );

$wp_customize->add_control( 'charity_give_theme_options[sponsor_title]', array(
	'label'             => sprintf( esc_html__( 'Title', 'charity-give' ) ),
	'section'        	=> 'charity_give_sponsor_section',
	'active_callback' 	=> 'charity_give_is_sponsor_section_enable',
	'type'				=> 'text',
	) );

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

// Title setting and control
$wp_customize->add_setting( 'charity_give_theme_options[sponsor_sub_title]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default' => $options['sponsor_sub_title'],
	'transport'			=> 'postMessage',
	) );

$wp_customize->add_control( 'charity_give_theme_options[sponsor_sub_title]', array(
	'label'             => sprintf( esc_html__( 'Sub Title', 'charity-give' ) ),
	'section'        	=> 'charity_give_sponsor_section',
	'active_callback' 	=> 'charity_give_is_sponsor_section_enable',
	'type'				=> 'text',
	) );

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


for ( $i = 1; $i <= 5; $i++ ) :

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

	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'charity_give_theme_options[sponsor_image_' . $i . ']',
			array(
			'label'       		=> sprintf( esc_html__( 'Image %d', 'charity-give' ), $i),
			'section'     		=> 'charity_give_sponsor_section',
			'active_callback'	=> 'charity_give_is_sponsor_section_enable',
	) ) );

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

	$wp_customize->add_control( 'charity_give_theme_options[sponsor_url_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Sponsor Url %d', 'charity-give' ), $i),
		'section'        	=> 'charity_give_sponsor_section',
		'active_callback' 	=> 'charity_give_is_sponsor_section_enable',
		'type'				=> 'url',
	) );

		// services hr setting and control
	$wp_customize->add_setting( 'charity_give_theme_options[sponsor_hr_'. $i .']', array(
		'sanitize_callback' => 'sanitize_text_field'
	) );

	$wp_customize->add_control( new Charity_Give_Customize_Horizontal_Line( $wp_customize, 'charity_give_theme_options[sponsor_hr_'. $i .']',
		array(
			'section'         => 'charity_give_sponsor_section',
			'active_callback' => 'charity_give_is_sponsor_section_enable',
			'type'			  => 'hr'
	) ) );

endfor;