<?php

if ( ! class_exists( 'Give' ) ) {
	return;
}

// Cause Section.
$wp_customize->add_section(
	'charity_elite_causes_section',
	array(
		'title'    => esc_html__( 'Cause Section', 'charity-elite' ),
		'panel'    => 'charity_elite_front_page_options',
		'priority' => 30,
	)
);

// Cause Section - Enable Section.
$wp_customize->add_setting(
	'charity_elite_enable_causes_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_causes_section',
		array(
			'label'    => esc_html__( 'Enable Cause Section', 'charity-elite' ),
			'section'  => 'charity_elite_causes_section',
			'settings' => 'charity_elite_enable_causes_section',
		)
	)
);

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

// Cause Section - Section Subtitle.
$wp_customize->add_setting(
	'charity_elite_causes_subtitle',
	array(
		'default'           => __( 'Give your help today', 'charity-elite' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_causes_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'charity-elite' ),
		'section'         => 'charity_elite_causes_section',
		'settings'        => 'charity_elite_causes_subtitle',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_causes_section_enabled',
	)
);

// Cause Section - Section Title.
$wp_customize->add_setting(
	'charity_elite_causes_title',
	array(
		'default'           => __( 'Help Poor people', 'charity-elite' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_causes_title',
	array(
		'label'           => esc_html__( 'Section Title', 'charity-elite' ),
		'section'         => 'charity_elite_causes_section',
		'settings'        => 'charity_elite_causes_title',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_causes_section_enabled',
	)
);

// Cause Section - Number of Posts.
$wp_customize->add_setting(
	'charity_elite_causes_counter',
	array(
		'default'           => 3,
		'sanitize_callback' => 'charity_elite_sanitize_number_range',
		'validate_callback' => 'charity_elite_validate_causes_count',
	)
);

$wp_customize->add_control(
	'charity_elite_causes_counter',
	array(
		'label'           => esc_html__( 'Number of Items to Show', 'charity-elite' ),
		'description'     => esc_html__( 'Note: Min 1 & Max 6. Please input the valid number and save. Then refresh the page to see the change.', 'charity-elite' ),
		'section'         => 'charity_elite_causes_section',
		'settings'        => 'charity_elite_causes_counter',
		'type'            => 'number',
		'input_attrs'     => array(
			'min' => 1,
			'max' => 6,
		),
		'active_callback' => 'charity_elite_is_causes_section_enabled',
	)
);

// List out selected number of fields.
$cause_count = get_theme_mod( 'charity_elite_causes_counter', 3 );

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

	// Banner Section - Select Banner Page.
	$wp_customize->add_setting(
		'charity_elite_causes_donation_form_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'charity_elite_causes_donation_form_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Form %d', 'charity-elite' ), $i ),
			'section'         => 'charity_elite_causes_section',
			'settings'        => 'charity_elite_causes_donation_form_' . $i,
			'active_callback' => 'charity_elite_is_causes_section_enabled',
			'type'            => 'select',
			'choices'         => charity_elite_get_post_donation_form_choices(),
		)
	);
}

// Cause Section - Button Label.
$wp_customize->add_setting(
	'charity_elite_causes_button_label',
	array(
		'default'           => __( 'Donate Now', 'charity-elite' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_causes_button_label',
	array(
		'label'           => esc_html__( 'Button Label', 'charity-elite' ),
		'section'         => 'charity_elite_causes_section',
		'settings'        => 'charity_elite_causes_button_label',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_causes_section_enabled',
	)
);
