<?php
function clothing_marketplace_sanitize_select( $clothing_marketplace_input, $clothing_marketplace_setting ) {
	$clothing_marketplace_input = sanitize_key( $clothing_marketplace_input );
	$clothing_marketplace_choices = $clothing_marketplace_setting->manager->get_control( $clothing_marketplace_setting->id )->choices;
	return ( array_key_exists( $clothing_marketplace_input, $clothing_marketplace_choices ) ? $clothing_marketplace_input : $clothing_marketplace_setting->default );
}

function clothing_marketplace_sanitize_switch( $clothing_marketplace_input ) {
	if ( true === $clothing_marketplace_input ) {
		return true;
	} else {
		return false;
	}
}

function clothing_marketplace_sanitize_google_fonts( $clothing_marketplace_input, $clothing_marketplace_setting ) {
	$clothing_marketplace_choices = $clothing_marketplace_setting->manager->get_control( $clothing_marketplace_setting->id )->choices;
	return ( array_key_exists( $clothing_marketplace_input, $clothing_marketplace_choices ) ? $clothing_marketplace_input : $clothing_marketplace_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $clothing_marketplace_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function clothing_marketplace_sanitize_html( $clothing_marketplace_input ) {
    return wp_kses_post( $clothing_marketplace_input );
}

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

function clothing_marketplace_sanitize_choices( $clothing_marketplace_input, $clothing_marketplace_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $clothing_marketplace_setting->id ); 
	if ( array_key_exists( $clothing_marketplace_input, $control->choices ) ) {
		return $clothing_marketplace_input;
	} else {
		return $clothing_marketplace_setting->default;
	}
}

function clothing_marketplace_sanitize_range_value( $clothing_marketplace_number, $clothing_marketplace_setting ) {

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

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

	// Get minimum number in the range.
	$clothing_marketplace_min = ( isset( $clothing_marketplace_atts['min'] ) ? $clothing_marketplace_atts['min'] : $clothing_marketplace_number );

	// Get maximum number in the range.
	$clothing_marketplace_max = ( isset( $clothing_marketplace_atts['max'] ) ? $clothing_marketplace_atts['max'] : $clothing_marketplace_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $clothing_marketplace_min <= $clothing_marketplace_number && $clothing_marketplace_number <= $clothing_marketplace_max && is_int( $clothing_marketplace_number / $clothing_marketplace_step ) ? $clothing_marketplace_number : $clothing_marketplace_setting->default );
}