<?php

function bike_workshop_sanitize_select( $bike_workshop_input, $bike_workshop_setting ) {
	$bike_workshop_input = sanitize_key( $bike_workshop_input );
	$bike_workshop_choices = $bike_workshop_setting->manager->get_control( $bike_workshop_setting->id )->choices;
	return ( array_key_exists( $bike_workshop_input, $bike_workshop_choices ) ? $bike_workshop_input : $bike_workshop_setting->default );
}

function bike_workshop_sanitize_switch( $bike_workshop_input ) {
	if ( true === $bike_workshop_input ) {
		return true;
	} else {
		return false;
	}
}

function bike_workshop_sanitize_google_fonts( $bike_workshop_input, $bike_workshop_setting ) {
	$bike_workshop_choices = $bike_workshop_setting->manager->get_control( $bike_workshop_setting->id )->choices;
	return ( array_key_exists( $bike_workshop_input, $bike_workshop_choices ) ? $bike_workshop_input : $bike_workshop_setting->default );
}

function bike_workshop_sanitize_choices( $bike_workshop_input, $bike_workshop_setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $bike_workshop_setting->id );
    if ( array_key_exists( $bike_workshop_input, $control->choices ) ) {
        return $bike_workshop_input;
    } else {
        return $bike_workshop_setting->default;
    }
}

/**
 * Sanitize HTML input.
 *
 * @param string $bike_workshop_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function bike_workshop_sanitize_html( $bike_workshop_input ) {
    return wp_kses_post( $bike_workshop_input );
}

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

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

function bike_workshop_sanitize_range_value( $bike_workshop_number, $bike_workshop_setting ) {

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

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

	// Get minimum number in the range.
	$bike_workshop_min = ( isset( $bike_workshop_atts['min'] ) ? $bike_workshop_atts['min'] : $bike_workshop_number );

	// Get maximum number in the range.
	$bike_workshop_max = ( isset( $bike_workshop_atts['max'] ) ? $bike_workshop_atts['max'] : $bike_workshop_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $bike_workshop_min <= $bike_workshop_number && $bike_workshop_number <= $bike_workshop_max && is_int( $bike_workshop_number / $bike_workshop_step ) ? $bike_workshop_number : $bike_workshop_setting->default );
}