<?php
/**
 * Counter Section
 *
 * @package Corporaze
 */

$wp_customize->add_section(
	'corporaze_counter_section',
	array(
		'panel'    => 'corporaze_front_page_options',
		'title'    => esc_html__( 'Counter Section', 'corporaze' ),
		'priority' => 50,
	)
);

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

$wp_customize->add_control(
	new Corporaze_Toggle_Switch_Custom_Control(
		$wp_customize,
		'corporaze_enable_counter_section',
		array(
			'label'    => esc_html__( 'Enable Counter Section', 'corporaze' ),
			'section'  => 'corporaze_counter_section',
			'settings' => 'corporaze_enable_counter_section',
		)
	)
);

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

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

$wp_customize->add_control(
	new WP_Customize_Image_Control(
		$wp_customize,
		'corporaze_counter_background_image',
		array(
			'label'           => esc_html__( 'Background Image', 'corporaze' ),
			'description'     => esc_html__( 'Background color will be replaced by image.', 'corporaze' ),
			'section'         => 'corporaze_counter_section',
			'settings'        => 'corporaze_counter_background_image',
			'active_callback' => 'corporaze_is_counter_section_enabled',
		)
	)
);

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

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

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'corporaze_counter_icon_' . $i,
			array(
				'label'           => sprintf( esc_html__( 'Icon %d', 'corporaze' ), $i ),
				'section'         => 'corporaze_counter_section',
				'settings'        => 'corporaze_counter_icon_' . $i,
				'active_callback' => 'corporaze_is_counter_section_enabled',
			)
		)
	);

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

	$wp_customize->add_control(
		'corporaze_counter_label_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Label %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_counter_section',
			'settings'        => 'corporaze_counter_label_' . $i,
			'type'            => 'text',
			'active_callback' => 'corporaze_is_counter_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'corporaze_counter_value_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Value %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_counter_section',
			'settings'        => 'corporaze_counter_value_' . $i,
			'type'            => 'number',
			'input_attrs'     => array( 'min' => 1 ),
			'active_callback' => 'corporaze_is_counter_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'corporaze_counter_value_suffix_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Value Suffix %d', 'corporaze' ), $i ),
			'section'         => 'corporaze_counter_section',
			'settings'        => 'corporaze_counter_value_suffix_' . $i,
			'type'            => 'text',
			'active_callback' => 'corporaze_is_counter_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		new Corporaze_Customize_Horizontal_Line(
			$wp_customize,
			'corporaze_counter_horizontal_line_' . $i,
			array(
				'section'         => 'corporaze_counter_section',
				'settings'        => 'corporaze_counter_horizontal_line_' . $i,
				'active_callback' => 'corporaze_is_counter_section_enabled',
				'type'            => 'hr',
			)
		)
	);

}
