<?php
function electrical_services_sanitize_select( $electrical_services_input, $electrical_services_setting ) {
	$electrical_services_input = sanitize_key( $electrical_services_input );
	$electrical_services_choices = $electrical_services_setting->manager->get_control( $electrical_services_setting->id )->choices;
	return ( array_key_exists( $electrical_services_input, $electrical_services_choices ) ? $electrical_services_input : $electrical_services_setting->default );
}

function electrical_services_sanitize_switch( $electrical_services_input ) {
	if ( true === $electrical_services_input ) {
		return true;
	} else {
		return false;
	}
}

function electrical_services_sanitize_google_fonts( $electrical_services_input, $electrical_services_setting ) {
	$electrical_services_choices = $electrical_services_setting->manager->get_control( $electrical_services_setting->id )->choices;
	return ( array_key_exists( $electrical_services_input, $electrical_services_choices ) ? $electrical_services_input : $electrical_services_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $electrical_services_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function electrical_services_sanitize_html( $electrical_services_input ) {
    return wp_kses_post( $electrical_services_input );
}

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

function electrical_services_sanitize_choices( $electrical_services_input, $electrical_services_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $electrical_services_setting->id ); 
	if ( array_key_exists( $electrical_services_input, $control->choices ) ) {
		return $electrical_services_input;
	} else {
		return $electrical_services_setting->default;
	}
}

function electrical_services_sanitize_range_value( $electrical_services_number, $electrical_services_setting ) {

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

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

	// Get minimum number in the range.
	$electrical_services_min = ( isset( $electrical_services_atts['min'] ) ? $electrical_services_atts['min'] : $electrical_services_number );

	// Get maximum number in the range.
	$electrical_services_max = ( isset( $electrical_services_atts['max'] ) ? $electrical_services_atts['max'] : $electrical_services_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $electrical_services_min <= $electrical_services_number && $electrical_services_number <= $electrical_services_max && is_int( $electrical_services_number / $electrical_services_step ) ? $electrical_services_number : $electrical_services_setting->default );
}