<?php
function charitable_funds_sanitize_select( $charitable_funds_input, $charitable_funds_setting ) {
	$charitable_funds_input = sanitize_key( $charitable_funds_input );
	$charitable_funds_choices = $charitable_funds_setting->manager->get_control( $charitable_funds_setting->id )->choices;
	return ( array_key_exists( $charitable_funds_input, $charitable_funds_choices ) ? $charitable_funds_input : $charitable_funds_setting->default );
}

function charitable_funds_sanitize_switch( $charitable_funds_input ) {
	if ( true === $charitable_funds_input ) {
		return true;
	} else {
		return false;
	}
}

function charitable_funds_sanitize_google_fonts( $charitable_funds_input, $charitable_funds_setting ) {
	$charitable_funds_choices = $charitable_funds_setting->manager->get_control( $charitable_funds_setting->id )->choices;
	return ( array_key_exists( $charitable_funds_input, $charitable_funds_choices ) ? $charitable_funds_input : $charitable_funds_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $charitable_funds_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function charitable_funds_sanitize_html( $charitable_funds_input ) {
    return wp_kses_post( $charitable_funds_input );
}

// Sanitize Scroll Top Position
function charitable_funds_sanitize_scroll_top_position( $charitable_funds_input ) {
    $valid_positions = array( 'bottom-right', 'bottom-left', 'bottom-center' );
    if ( in_array( $charitable_funds_input, $valid_positions ) ) {
        return $charitable_funds_input;
    } else {
        return 'bottom-right'; // Default to bottom-right if invalid value
    }
}

function charitable_funds_sanitize_choices( $charitable_funds_input, $charitable_funds_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $charitable_funds_setting->id ); 
	if ( array_key_exists( $charitable_funds_input, $control->choices ) ) {
		return $charitable_funds_input;
	} else {
		return $charitable_funds_setting->default;
	}
}

function charitable_funds_sanitize_range_value( $charitable_funds_number, $charitable_funds_setting ) {

	// Ensure input is an absolute integer.
	$charitable_funds_number = absint( $charitable_funds_number );

	// Get the input attributes associated with the setting.
	$charitable_funds_atts = $charitable_funds_setting->manager->get_control( $charitable_funds_setting->id )->input_attrs;

	// Get minimum number in the range.
	$charitable_funds_min = ( isset( $charitable_funds_atts['min'] ) ? $charitable_funds_atts['min'] : $charitable_funds_number );

	// Get maximum number in the range.
	$charitable_funds_max = ( isset( $charitable_funds_atts['max'] ) ? $charitable_funds_atts['max'] : $charitable_funds_number );

	// Get step.
	$charitable_funds_step = ( isset( $charitable_funds_atts['step'] ) ? $charitable_funds_atts['step'] : 1 );

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $charitable_funds_min <= $charitable_funds_number && $charitable_funds_number <= $charitable_funds_max && is_int( $charitable_funds_number / $charitable_funds_step ) ? $charitable_funds_number : $charitable_funds_setting->default );
}