<?php
/**
 * Skills Section options
 *
 * @package Theme Palace
 * @subpackage Blog Diary Pro
 * @since Blog Diary Pro 1.0.0
 */

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

// Skills content enable control and setting
$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_section_enable]', array(
	'default'			=> 	$options['skills_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[skills_section_enable]', array(
	'label'             => esc_html__( 'Skills Section Enable', 'raise-charity-pro' ),
	'section'           => 'raise_charity_pro_skills_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[skills_section_enable]', array(
		'selector'            => '#skills-section .tooltiptext',
		'settings'            => 'raise_charity_pro_theme_options[skills_section_enable]',
    ) );
}

// skills title setting and control
$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_title]',
	array(
		'default'       		=> $options['skills_title'],
		'sanitize_callback'		=> 'sanitize_text_field',
		'transport'				=> 'postMessage',
	)
);
$wp_customize->add_control( 'raise_charity_pro_theme_options[skills_title]',
    array(
		'label'      			=> esc_html__( 'Section Title', 'raise-charity-pro' ),
		'section'    			=> 'raise_charity_pro_skills_section',
		'type'		 			=> 'text',
		'active_callback'		=> 'raise_charity_pro_is_skills_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[skills_title]', array(
		'selector'            => '#skills-section h2.section-title',
		'settings'            => 'raise_charity_pro_theme_options[skills_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'raise_charity_pro_skills_title_partial',
    ) );
}

// skills title setting and control
$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_sub_title]',
	array(
		'default'       		=> $options['skills_sub_title'],
		'sanitize_callback'		=> 'wp_kses_post',
		'transport'				=> 'postMessage',
	)
);
$wp_customize->add_control( 'raise_charity_pro_theme_options[skills_sub_title]',
    array(
		'label'      			=> esc_html__( 'Section Sub Title', 'raise-charity-pro' ),
		'section'    			=> 'raise_charity_pro_skills_section',
		'type'		 			=> 'textarea',
		'active_callback'		=> 'raise_charity_pro_is_skills_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[skills_sub_title]', array(
		'selector'            => '#skills-section p.section-subtitle',
		'settings'            => 'raise_charity_pro_theme_options[skills_sub_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'raise_charity_pro_skills_sub_title_partial',
    ) );
}


// skills title setting and control
$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_content]',
	array(
		'default'       		=> $options['skills_content'],
		'sanitize_callback'		=> 'wp_kses_post',
	)
);
$wp_customize->add_control( 'raise_charity_pro_theme_options[skills_content]',
    array(
		'label'      			=> esc_html__( 'Section Content', 'raise-charity-pro' ),
		'section'    			=> 'raise_charity_pro_skills_section',
		'type'		 			=> 'textarea',
		'active_callback'		=> 'raise_charity_pro_is_skills_section_enable',
    )
);

// skills number control and setting
$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_count]', array(
	'default'          	=> $options['skills_count'],
	'sanitize_callback' => 'raise_charity_pro_sanitize_number_range',
	'validate_callback' => 'raise_charity_pro_validate_skills_count',
) );

$wp_customize->add_control( 'raise_charity_pro_theme_options[skills_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_skills_section',
	'active_callback'   => 'raise_charity_pro_is_skills_section_enable',
	'type'				=> 'number',
	'input_attrs'		=> array(
		'min'	=> 1,
		'max'	=> 20,
		'style' => 'width: 100px;'
		),
) );

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

	// skills title setting and control
	$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_name_' . $i . ']', array(
		'sanitize_callback' => 'sanitize_text_field',
	) );

	$wp_customize->add_control( 'raise_charity_pro_theme_options[skills_name_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Skill Name %d', 'raise-charity-pro' ), $i ),
		'section'        	=> 'raise_charity_pro_skills_section',
		'active_callback' 	=> 'raise_charity_pro_is_skills_section_enable',
		'type'				=> 'text',
	) );

	// skills position setting and control
	$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_percentage_' . $i . ']', array(
		'sanitize_callback' => 'sanitize_text_field',
	) );

	$wp_customize->add_control( 'raise_charity_pro_theme_options[skills_percentage_' . $i . ']', array(
		'label'           	=> sprintf( esc_html__( 'Skill Percentage %d', 'raise-charity-pro' ), $i ),
		'section'        	=> 'raise_charity_pro_skills_section',
		'active_callback' 	=> 'raise_charity_pro_is_skills_section_enable',
		'type'				=> 'text',
	) );

	// skills hr setting and control
	$wp_customize->add_setting( 'raise_charity_pro_theme_options[skills_hr_'. $i .']', array(
		'sanitize_callback' => 'sanitize_text_field'
	) );

	$wp_customize->add_control( new Raise_Charity_Pro_Customize_Horizontal_Line( $wp_customize, 'raise_charity_pro_theme_options[skills_hr_'. $i .']',
		array(
			'section'         => 'raise_charity_pro_skills_section',
			'active_callback' => 'raise_charity_pro_is_skills_section_enable',
			'type'			  => 'hr'
	) ) );
endfor;