<?php
function aster_it_courses_sanitize_select( $aster_it_courses_input, $aster_it_courses_setting ) {
	$aster_it_courses_input = sanitize_key( $aster_it_courses_input );
	$aster_it_courses_choices = $aster_it_courses_setting->manager->get_control( $aster_it_courses_setting->id )->choices;
	return ( array_key_exists( $aster_it_courses_input, $aster_it_courses_choices ) ? $aster_it_courses_input : $aster_it_courses_setting->default );
}

function aster_it_courses_sanitize_switch( $aster_it_courses_input ) {
	if ( true === $aster_it_courses_input ) {
		return true;
	} else {
		return false;
	}
}

function aster_it_courses_sanitize_google_fonts( $aster_it_courses_input, $aster_it_courses_setting ) {
	$aster_it_courses_choices = $aster_it_courses_setting->manager->get_control( $aster_it_courses_setting->id )->choices;
	return ( array_key_exists( $aster_it_courses_input, $aster_it_courses_choices ) ? $aster_it_courses_input : $aster_it_courses_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $aster_it_courses_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function aster_it_courses_sanitize_html( $aster_it_courses_input ) {
    return wp_kses_post( $aster_it_courses_input );
}

/**
 * Sanitize URL input.
 *
 * @param string $aster_it_courses_input URL input to sanitize.
 * @return string Sanitized URL.
 */
function aster_it_courses_sanitize_url( $aster_it_courses_input ) {
    return esc_url_raw( $aster_it_courses_input );
}

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

function aster_it_courses_sanitize_choices( $aster_it_courses_input, $aster_it_courses_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $aster_it_courses_setting->id ); 
	if ( array_key_exists( $aster_it_courses_input, $control->choices ) ) {
		return $aster_it_courses_input;
	} else {
		return $aster_it_courses_setting->default;
	}
}

function aster_it_courses_sanitize_range_value( $aster_it_courses_number, $aster_it_courses_setting ) {

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

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

	// Get minimum number in the range.
	$aster_it_courses_min = ( isset( $aster_it_courses_atts['min'] ) ? $aster_it_courses_atts['min'] : $aster_it_courses_number );

	// Get maximum number in the range.
	$aster_it_courses_max = ( isset( $aster_it_courses_atts['max'] ) ? $aster_it_courses_atts['max'] : $aster_it_courses_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $aster_it_courses_min <= $aster_it_courses_number && $aster_it_courses_number <= $aster_it_courses_max && is_int( $aster_it_courses_number / $aster_it_courses_step ) ? $aster_it_courses_number : $aster_it_courses_setting->default );
}