<?php
function jewelry_accessories_sanitize_select( $jewelry_accessories_input, $jewelry_accessories_setting ) {
	$jewelry_accessories_input = sanitize_key( $jewelry_accessories_input );
	$jewelry_accessories_choices = $jewelry_accessories_setting->manager->get_control( $jewelry_accessories_setting->id )->choices;
	return ( array_key_exists( $jewelry_accessories_input, $jewelry_accessories_choices ) ? $jewelry_accessories_input : $jewelry_accessories_setting->default );
}

function jewelry_accessories_sanitize_switch( $jewelry_accessories_input ) {
	if ( true === $jewelry_accessories_input ) {
		return true;
	} else {
		return false;
	}
}

function jewelry_accessories_sanitize_google_fonts( $jewelry_accessories_input, $jewelry_accessories_setting ) {
	$jewelry_accessories_choices = $jewelry_accessories_setting->manager->get_control( $jewelry_accessories_setting->id )->choices;
	return ( array_key_exists( $jewelry_accessories_input, $jewelry_accessories_choices ) ? $jewelry_accessories_input : $jewelry_accessories_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $jewelry_accessories_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function jewelry_accessories_sanitize_html( $jewelry_accessories_input ) {
    return wp_kses_post( $jewelry_accessories_input );
}

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

function jewelry_accessories_sanitize_choices( $jewelry_accessories_input, $jewelry_accessories_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $jewelry_accessories_setting->id ); 
	if ( array_key_exists( $jewelry_accessories_input, $control->choices ) ) {
		return $jewelry_accessories_input;
	} else {
		return $jewelry_accessories_setting->default;
	}
}

function jewelry_accessories_sanitize_range_value( $jewelry_accessories_number, $jewelry_accessories_setting ) {

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

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

	// Get minimum number in the range.
	$jewelry_accessories_min = ( isset( $jewelry_accessories_atts['min'] ) ? $jewelry_accessories_atts['min'] : $jewelry_accessories_number );

	// Get maximum number in the range.
	$jewelry_accessories_max = ( isset( $jewelry_accessories_atts['max'] ) ? $jewelry_accessories_atts['max'] : $jewelry_accessories_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $jewelry_accessories_min <= $jewelry_accessories_number && $jewelry_accessories_number <= $jewelry_accessories_max && is_int( $jewelry_accessories_number / $jewelry_accessories_step ) ? $jewelry_accessories_number : $jewelry_accessories_setting->default );
}