<?php

/**
 * Counter Section
 *
 * @package Charity_Elite
 */

$wp_customize->add_section(
	'charity_elite_counter_section',
	array(
		'panel'    => 'charity_elite_front_page_options',
		'title'    => esc_html__( 'Counter Section', 'charity-elite' ),
		'priority' => 50,
	)
);

// Counter Section - Enable Section.
$wp_customize->add_setting(
	'charity_elite_enable_counter_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'charity_elite_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Charity_Elite_Toggle_Switch_Custom_Control(
		$wp_customize,
		'charity_elite_enable_counter_section',
		array(
			'label'    => esc_html__( 'Enable Counter Section', 'charity-elite' ),
			'section'  => 'charity_elite_counter_section',
			'settings' => 'charity_elite_enable_counter_section',
		)
	)
);

if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'charity_elite_enable_counter_section',
		array(
			'selector' => '#charity_elite_counter_section .section-link',
			'settings' => 'charity_elite_enable_counter_section',
		)
	);
}

// Counter Section - Background Image.
$wp_customize->add_setting(
	'charity_elite_counter_bg_image',
	array(
		'sanitize_callback' => 'charity_elite_sanitize_image',
	)
);

$wp_customize->add_control(
	new WP_Customize_Image_Control(
		$wp_customize,
		'charity_elite_counter_bg_image',
		array(
			'label'           => esc_html__( 'Background Image', 'charity-elite' ),
			'section'         => 'charity_elite_counter_section',
			'settings'        => 'charity_elite_counter_bg_image',
			'active_callback' => 'charity_elite_is_counter_section_enabled',
		)
	)
);

// Counter Section - Section Subtitle.
$wp_customize->add_setting(
	'charity_elite_counter_subtitle',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_counter_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'charity-elite' ),
		'section'         => 'charity_elite_counter_section',
		'settings'        => 'charity_elite_counter_subtitle',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_counter_section_enabled',
	)
);

// Counter Section - Section Title.
$wp_customize->add_setting(
	'charity_elite_counter_title',
	array(
		'default'           => __( 'Our Achivements', 'charity-elite' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_counter_title',
	array(
		'label'           => esc_html__( 'Section Title', 'charity-elite' ),
		'section'         => 'charity_elite_counter_section',
		'settings'        => 'charity_elite_counter_title',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_counter_section_enabled',
	)
);

for ( $i = 1; $i <= 4; $i++ ) {

	// Counter Section - Counter Icon.
	$wp_customize->add_setting(
		'charity_elite_counter_icon_' . $i,
		array(
			'sanitize_callback' => 'charity_elite_sanitize_image',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'charity_elite_counter_icon_' . $i,
			array(
				'label'           => sprintf( esc_html__( 'Icon %d', 'charity-elite' ), $i ),
				'section'         => 'charity_elite_counter_section',
				'settings'        => 'charity_elite_counter_icon_' . $i,
				'active_callback' => 'charity_elite_is_counter_section_enabled',
			)
		)
	);

	// Counter Section - Counter Label.
	$wp_customize->add_setting(
		'charity_elite_counter_label_' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'charity_elite_counter_label_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Label %d', 'charity-elite' ), $i ),
			'section'         => 'charity_elite_counter_section',
			'settings'        => 'charity_elite_counter_label_' . $i,
			'type'            => 'text',
			'active_callback' => 'charity_elite_is_counter_section_enabled',
		)
	);

	// Counter Section - Counter Value.
	$wp_customize->add_setting(
		'charity_elite_counter_value_' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'charity_elite_counter_value_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Value %d', 'charity-elite' ), $i ),
			'section'         => 'charity_elite_counter_section',
			'settings'        => 'charity_elite_counter_value_' . $i,
			'type'            => 'number',
			'input_attrs'     => array( 'min' => 1 ),
			'active_callback' => 'charity_elite_is_counter_section_enabled',
		)
	);

	// Counter Section - Counter Suffix.
	$wp_customize->add_setting(
		'charity_elite_counter_value_suffix_' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'charity_elite_counter_value_suffix_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Value Suffix %d', 'charity-elite' ), $i ),
			'section'         => 'charity_elite_counter_section',
			'settings'        => 'charity_elite_counter_value_suffix_' . $i,
			'type'            => 'text',
			'active_callback' => 'charity_elite_is_counter_section_enabled',
		)
	);

	// Counter Section - Horizontal Line.
	$wp_customize->add_setting(
		'charity_elite_counter_horizontal_line_' . $i,
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		new Charity_Elite_Customize_Horizontal_Line(
			$wp_customize,
			'charity_elite_counter_horizontal_line_' . $i,
			array(
				'section'         => 'charity_elite_counter_section',
				'settings'        => 'charity_elite_counter_horizontal_line_' . $i,
				'active_callback' => 'charity_elite_is_counter_section_enabled',
				'type'            => 'hr',
			)
		)
	);
}
