<?php
function appointment_management_sanitize_select( $appointment_management_input, $appointment_management_setting ) {
	$appointment_management_input = sanitize_key( $appointment_management_input );
	$appointment_management_choices = $appointment_management_setting->manager->get_control( $appointment_management_setting->id )->choices;
	return ( array_key_exists( $appointment_management_input, $appointment_management_choices ) ? $appointment_management_input : $appointment_management_setting->default );
}

function appointment_management_sanitize_switch( $appointment_management_input ) {
	if ( true === $appointment_management_input ) {
		return true;
	} else {
		return false;
	}
}

function appointment_management_sanitize_google_fonts( $appointment_management_input, $appointment_management_setting ) {
	$appointment_management_choices = $appointment_management_setting->manager->get_control( $appointment_management_setting->id )->choices;
	return ( array_key_exists( $appointment_management_input, $appointment_management_choices ) ? $appointment_management_input : $appointment_management_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $appointment_management_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function appointment_management_sanitize_html( $appointment_management_input ) {
    return wp_kses_post( $appointment_management_input );
}

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

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

function appointment_management_sanitize_choices( $appointment_management_input, $appointment_management_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $appointment_management_setting->id ); 
	if ( array_key_exists( $appointment_management_input, $control->choices ) ) {
		return $appointment_management_input;
	} else {
		return $appointment_management_setting->default;
	}
}

function appointment_management_sanitize_range_value( $appointment_management_number, $appointment_management_setting ) {

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

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

	// Get minimum number in the range.
	$appointment_management_min = ( isset( $appointment_management_atts['min'] ) ? $appointment_management_atts['min'] : $appointment_management_number );

	// Get maximum number in the range.
	$appointment_management_max = ( isset( $appointment_management_atts['max'] ) ? $appointment_management_atts['max'] : $appointment_management_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $appointment_management_min <= $appointment_management_number && $appointment_management_number <= $appointment_management_max && is_int( $appointment_management_number / $appointment_management_step ) ? $appointment_management_number : $appointment_management_setting->default );
}