<?php
function online_school_courses_sanitize_select( $online_school_courses_input, $online_school_courses_setting ) {
	$online_school_courses_input = sanitize_key( $online_school_courses_input );
	$online_school_courses_choices = $online_school_courses_setting->manager->get_control( $online_school_courses_setting->id )->choices;
	return ( array_key_exists( $online_school_courses_input, $online_school_courses_choices ) ? $online_school_courses_input : $online_school_courses_setting->default );
}

function online_school_courses_sanitize_switch( $online_school_courses_input ) {
	if ( true === $online_school_courses_input ) {
		return true;
	} else {
		return false;
	}
}

function online_school_courses_sanitize_google_fonts( $online_school_courses_input, $online_school_courses_setting ) {
	$online_school_courses_choices = $online_school_courses_setting->manager->get_control( $online_school_courses_setting->id )->choices;
	return ( array_key_exists( $online_school_courses_input, $online_school_courses_choices ) ? $online_school_courses_input : $online_school_courses_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $online_school_courses_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function online_school_courses_sanitize_html( $online_school_courses_input ) {
    return wp_kses_post( $online_school_courses_input );
}

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

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

function online_school_courses_sanitize_choices( $online_school_courses_input, $online_school_courses_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $online_school_courses_setting->id ); 
	if ( array_key_exists( $online_school_courses_input, $control->choices ) ) {
		return $online_school_courses_input;
	} else {
		return $online_school_courses_setting->default;
	}
}

function online_school_courses_sanitize_range_value( $online_school_courses_number, $online_school_courses_setting ) {

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

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

	// Get minimum number in the range.
	$online_school_courses_min = ( isset( $online_school_courses_atts['min'] ) ? $online_school_courses_atts['min'] : $online_school_courses_number );

	// Get maximum number in the range.
	$online_school_courses_max = ( isset( $online_school_courses_atts['max'] ) ? $online_school_courses_atts['max'] : $online_school_courses_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $online_school_courses_min <= $online_school_courses_number && $online_school_courses_number <= $online_school_courses_max && is_int( $online_school_courses_number / $online_school_courses_step ) ? $online_school_courses_number : $online_school_courses_setting->default );
}