<?php
function jeweler_shop_sanitize_select( $jeweler_shop_input, $jeweler_shop_setting ) {
	$jeweler_shop_input = sanitize_key( $jeweler_shop_input );
	$jeweler_shop_choices = $jeweler_shop_setting->manager->get_control( $jeweler_shop_setting->id )->choices;
	return ( array_key_exists( $jeweler_shop_input, $jeweler_shop_choices ) ? $jeweler_shop_input : $jeweler_shop_setting->default );
}

function jeweler_shop_sanitize_switch( $jeweler_shop_input ) {
	if ( true === $jeweler_shop_input ) {
		return true;
	} else {
		return false;
	}
}

function jeweler_shop_sanitize_google_fonts( $jeweler_shop_input, $jeweler_shop_setting ) {
	$jeweler_shop_choices = $jeweler_shop_setting->manager->get_control( $jeweler_shop_setting->id )->choices;
	return ( array_key_exists( $jeweler_shop_input, $jeweler_shop_choices ) ? $jeweler_shop_input : $jeweler_shop_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $jeweler_shop_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function jeweler_shop_sanitize_html( $jeweler_shop_input ) {
    return wp_kses_post( $jeweler_shop_input );
}

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

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

function jeweler_shop_sanitize_choices( $jeweler_shop_input, $jeweler_shop_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $jeweler_shop_setting->id ); 
	if ( array_key_exists( $jeweler_shop_input, $control->choices ) ) {
		return $jeweler_shop_input;
	} else {
		return $jeweler_shop_setting->default;
	}
}

function jeweler_shop_sanitize_range_value( $jeweler_shop_number, $jeweler_shop_setting ) {

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

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

	// Get minimum number in the range.
	$jeweler_shop_min = ( isset( $jeweler_shop_atts['min'] ) ? $jeweler_shop_atts['min'] : $jeweler_shop_number );

	// Get maximum number in the range.
	$jeweler_shop_max = ( isset( $jeweler_shop_atts['max'] ) ? $jeweler_shop_atts['max'] : $jeweler_shop_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $jeweler_shop_min <= $jeweler_shop_number && $jeweler_shop_number <= $jeweler_shop_max && is_int( $jeweler_shop_number / $jeweler_shop_step ) ? $jeweler_shop_number : $jeweler_shop_setting->default );
}