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

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

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

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

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

$wp_customize->add_setting( 'charity_give_theme_options[about_btn_text]', array(
	'sanitize_callback' => 'sanitize_text_field',
	'default'			=> $options['about_btn_text'],
	'transport'			=> 'postMessage',
) );

$wp_customize->add_control( 'charity_give_theme_options[about_btn_text]', array(
	'label'           	=> esc_html__( 'Button Label', 'charity-give' ),
	'section'        	=> 'charity_give_about_section',
	'active_callback' 	=> 'charity_give_is_about_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[about_btn_text]', array(
		'selector'            => '#charity_give_about_section .read-more',
		'settings'            => 'charity_give_theme_options[about_btn_text]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'charity_give_about_btn_text_partial',
    ) );
}


$wp_customize->add_setting( 'charity_give_theme_options[about_excerpt_length]', array(
	'sanitize_callback' => 'charity_give_sanitize_number_range',
	'validate_callback' => 'charity_give_validate_long_excerpt',
	'default'			=> $options['about_excerpt_length'],
	) );

$wp_customize->add_control( 'charity_give_theme_options[about_excerpt_length]', array(
	'label'       		=> esc_html__( 'Excerpt Length', 'charity-give' ),
	'description' 		=> esc_html__( 'Total description words to be displayed in About posts.', 'charity-give' ),
	'section'     		=> 'charity_give_about_section',
	'active_callback' 	=> 'charity_give_is_about_section_enable',
	'type'        		=> 'number',
	'input_attrs' 		=> array(
		'style'       => 'width: 80px;',
		'max'         => 100,
		'min'         => 5,
		),
	) );

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

	// Service section title control and setting
	$wp_customize->add_setting( 'charity_give_theme_options[about_sub_title_' . $i . ']', 
		array(
			'sanitize_callback' => 'sanitize_text_field',
			'transport'			=>'postMessage',
		) 
	);

	$wp_customize->add_control('charity_give_theme_options[about_sub_title_' . $i . ']', 
		array(
			'label'             => sprintf( esc_html__( 'Sub Title %d', 'charity-give' ), $i ),
			'section'           => 'charity_give_about_section',
			'type'              =>'text',
			'active_callback'	=> 'charity_give_is_about_section_enable',
		)
	);

// About pages drop down chooser control and setting
$wp_customize->add_setting( 'charity_give_theme_options[about_content_page_' . $i . ']', array(
	'sanitize_callback' => 'charity_give_sanitize_page',
	) );

$wp_customize->add_control( new Charity_Give_Dropdown_Chooser( $wp_customize, 'charity_give_theme_options[about_content_page_' . $i . ']', array(
	'label'             => sprintf( esc_html__( 'Select Page %d', 'charity-give' ), $i ),
	'section'           => 'charity_give_about_section',
	'choices'			=> charity_give_page_choices(),
	'active_callback'	=> 'charity_give_is_about_section_enable',
	) ) );
endfor;