<?php

function bridal_jewelry_store_sanitize_select( $bridal_jewelry_store_input, $bridal_jewelry_store_setting ) {
	$bridal_jewelry_store_input = sanitize_key( $bridal_jewelry_store_input );
	$bridal_jewelry_store_choices = $bridal_jewelry_store_setting->manager->get_control( $bridal_jewelry_store_setting->id )->choices;
	return ( array_key_exists( $bridal_jewelry_store_input, $bridal_jewelry_store_choices ) ? $bridal_jewelry_store_input : $bridal_jewelry_store_setting->default );
}

function bridal_jewelry_store_sanitize_switch( $bridal_jewelry_store_input ) {
	if ( true === $bridal_jewelry_store_input ) {
		return true;
	} else {
		return false;
	}
}

function bridal_jewelry_store_sanitize_google_fonts( $bridal_jewelry_store_input, $bridal_jewelry_store_setting ) {
	$bridal_jewelry_store_choices = $bridal_jewelry_store_setting->manager->get_control( $bridal_jewelry_store_setting->id )->choices;
	return ( array_key_exists( $bridal_jewelry_store_input, $bridal_jewelry_store_choices ) ? $bridal_jewelry_store_input : $bridal_jewelry_store_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $bridal_jewelry_store_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function bridal_jewelry_store_sanitize_html( $bridal_jewelry_store_input ) {
    return wp_kses_post( $bridal_jewelry_store_input );
}

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

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

function bridal_jewelry_store_sanitize_image( $bridal_jewelry_store_image, $bridal_jewelry_store_setting ) {
	/*
	* Array of valid image file types.
	*
	* The array includes image mime types that are included in wp_get_mime_types()
	*/
	$mimes = array(
		'jpg|jpeg|jpe' => 'image/jpeg',
		'gif'          => 'image/gif',
		'png'          => 'image/png',
		'bmp'          => 'image/bmp',
		'tif|tiff'     => 'image/tiff',
		'ico'          => 'image/x-icon',
		'svg'          => 'image/svg+xml',
	);
	// Return an array with file extension and mime_type.
	$bridal_jewelry_store_file = wp_check_filetype( $bridal_jewelry_store_image, $mimes );
	// If $bridal_jewelry_store_image has a valid mime_type, return it; otherwise, return the default.
	return ( $bridal_jewelry_store_file['ext'] ? $bridal_jewelry_store_image : $bridal_jewelry_store_setting->default );
}

function bridal_jewelry_store_sanitize_choices( $bridal_jewelry_store_input, $bridal_jewelry_store_setting ) {
    global $wp_customize; 
    $bridal_jewelry_store_control = $wp_customize->get_control( $bridal_jewelry_store_setting->id ); 
    if ( array_key_exists( $bridal_jewelry_store_input, $bridal_jewelry_store_control->choices ) ) {
        return $bridal_jewelry_store_input;
    } else {
        return $bridal_jewelry_store_setting->default;
    }
}

function bridal_jewelry_store_sanitize_range_value( $bridal_jewelry_store_number, $bridal_jewelry_store_setting ) {

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

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

	// Get minimum number in the range.
	$bridal_jewelry_store_min = ( isset( $bridal_jewelry_store_atts['min'] ) ? $bridal_jewelry_store_atts['min'] : $bridal_jewelry_store_number );

	// Get maximum number in the range.
	$bridal_jewelry_store_max = ( isset( $bridal_jewelry_store_atts['max'] ) ? $bridal_jewelry_store_atts['max'] : $bridal_jewelry_store_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $bridal_jewelry_store_min <= $bridal_jewelry_store_number && $bridal_jewelry_store_number <= $bridal_jewelry_store_max && is_int( $bridal_jewelry_store_number / $bridal_jewelry_store_step ) ? $bridal_jewelry_store_number : $bridal_jewelry_store_setting->default );
}