<?php
function property_dealer_sanitize_select( $property_dealer_input, $property_dealer_setting ) {
	$property_dealer_input = sanitize_key( $property_dealer_input );
	$property_dealer_choices = $property_dealer_setting->manager->get_control( $property_dealer_setting->id )->choices;
	return ( array_key_exists( $property_dealer_input, $property_dealer_choices ) ? $property_dealer_input : $property_dealer_setting->default );
}

function property_dealer_sanitize_switch( $property_dealer_input ) {
	if ( true === $property_dealer_input ) {
		return true;
	} else {
		return false;
	}
}

function property_dealer_sanitize_google_fonts( $property_dealer_input, $property_dealer_setting ) {
	$property_dealer_choices = $property_dealer_setting->manager->get_control( $property_dealer_setting->id )->choices;
	return ( array_key_exists( $property_dealer_input, $property_dealer_choices ) ? $property_dealer_input : $property_dealer_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $property_dealer_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function property_dealer_sanitize_html( $property_dealer_input ) {
    return wp_kses_post( $property_dealer_input );
}

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

function property_dealer_sanitize_choices( $property_dealer_input, $property_dealer_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $property_dealer_setting->id ); 
	if ( array_key_exists( $property_dealer_input, $control->choices ) ) {
		return $property_dealer_input;
	} else {
		return $property_dealer_setting->default;
	}
}

function property_dealer_sanitize_range_value( $property_dealer_number, $property_dealer_setting ) {

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

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

	// Get minimum number in the range.
	$property_dealer_min = ( isset( $property_dealer_atts['min'] ) ? $property_dealer_atts['min'] : $property_dealer_number );

	// Get maximum number in the range.
	$property_dealer_max = ( isset( $property_dealer_atts['max'] ) ? $property_dealer_atts['max'] : $property_dealer_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $property_dealer_min <= $property_dealer_number && $property_dealer_number <= $property_dealer_max && is_int( $property_dealer_number / $property_dealer_step ) ? $property_dealer_number : $property_dealer_setting->default );
}