<?php

function cleaning_services_agent_sanitize_select( $cleaning_services_agent_input, $cleaning_services_agent_setting ) {
	$cleaning_services_agent_input = sanitize_key( $cleaning_services_agent_input );
	$cleaning_services_agent_choices = $cleaning_services_agent_setting->manager->get_control( $cleaning_services_agent_setting->id )->choices;
	return ( array_key_exists( $cleaning_services_agent_input, $cleaning_services_agent_choices ) ? $cleaning_services_agent_input : $cleaning_services_agent_setting->default );
}

function cleaning_services_agent_sanitize_switch( $cleaning_services_agent_input ) {
	if ( true === $cleaning_services_agent_input ) {
		return true;
	} else {
		return false;
	}
}

function cleaning_services_agent_sanitize_google_fonts( $cleaning_services_agent_input, $cleaning_services_agent_setting ) {
	$cleaning_services_agent_choices = $cleaning_services_agent_setting->manager->get_control( $cleaning_services_agent_setting->id )->choices;
	return ( array_key_exists( $cleaning_services_agent_input, $cleaning_services_agent_choices ) ? $cleaning_services_agent_input : $cleaning_services_agent_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $cleaning_services_agent_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function cleaning_services_agent_sanitize_html( $cleaning_services_agent_input ) {
    return wp_kses_post( $cleaning_services_agent_input );
}

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

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

function cleaning_services_agent_sanitize_choices( $cleaning_services_agent_input, $cleaning_services_agent_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $cleaning_services_agent_setting->id ); 
	if ( array_key_exists( $cleaning_services_agent_input, $control->choices ) ) {
		return $cleaning_services_agent_input;
	} else {
		return $cleaning_services_agent_setting->default;
	}
}

function cleaning_services_agent_sanitize_range_value( $cleaning_services_agent_number, $cleaning_services_agent_setting ) {

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

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

	// Get minimum number in the range.
	$cleaning_services_agent_min = ( isset( $cleaning_services_agent_atts['min'] ) ? $cleaning_services_agent_atts['min'] : $cleaning_services_agent_number );

	// Get maximum number in the range.
	$cleaning_services_agent_max = ( isset( $cleaning_services_agent_atts['max'] ) ? $cleaning_services_agent_atts['max'] : $cleaning_services_agent_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $cleaning_services_agent_min <= $cleaning_services_agent_number && $cleaning_services_agent_number <= $cleaning_services_agent_max && is_int( $cleaning_services_agent_number / $cleaning_services_agent_step ) ? $cleaning_services_agent_number : $cleaning_services_agent_setting->default );
}