<?php
function design_studio_sanitize_select( $design_studio_input, $design_studio_setting ) {
	$design_studio_input = sanitize_key( $design_studio_input );
	$design_studio_choices = $design_studio_setting->manager->get_control( $design_studio_setting->id )->choices;
	return ( array_key_exists( $design_studio_input, $design_studio_choices ) ? $design_studio_input : $design_studio_setting->default );
}

function design_studio_sanitize_switch( $design_studio_input ) {
	if ( true === $design_studio_input ) {
		return true;
	} else {
		return false;
	}
}

function design_studio_sanitize_google_fonts( $design_studio_input, $design_studio_setting ) {
	$design_studio_choices = $design_studio_setting->manager->get_control( $design_studio_setting->id )->choices;
	return ( array_key_exists( $design_studio_input, $design_studio_choices ) ? $design_studio_input : $design_studio_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $design_studio_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function design_studio_sanitize_html( $design_studio_input ) {
    return wp_kses_post( $design_studio_input );
}

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

function design_studio_sanitize_choices( $design_studio_input, $design_studio_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $design_studio_setting->id ); 
	if ( array_key_exists( $design_studio_input, $control->choices ) ) {
		return $design_studio_input;
	} else {
		return $design_studio_setting->default;
	}
}

function design_studio_sanitize_range_value( $design_studio_number, $design_studio_setting ) {

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

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

	// Get minimum number in the range.
	$design_studio_min = ( isset( $design_studio_atts['min'] ) ? $design_studio_atts['min'] : $design_studio_number );

	// Get maximum number in the range.
	$design_studio_max = ( isset( $design_studio_atts['max'] ) ? $design_studio_atts['max'] : $design_studio_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $design_studio_min <= $design_studio_number && $design_studio_number <= $design_studio_max && is_int( $design_studio_number / $design_studio_step ) ? $design_studio_number : $design_studio_setting->default );
}