<?php

function doctor_physician_sanitize_select( $doctor_physician_input, $doctor_physician_setting ) {
	$doctor_physician_input = sanitize_key( $doctor_physician_input );
	$doctor_physician_choices = $doctor_physician_setting->manager->get_control( $doctor_physician_setting->id )->choices;
	return ( array_key_exists( $doctor_physician_input, $doctor_physician_choices ) ? $doctor_physician_input : $doctor_physician_setting->default );
}

function doctor_physician_sanitize_switch( $doctor_physician_input ) {
	if ( true === $doctor_physician_input ) {
		return true;
	} else {
		return false;
	}
}

function doctor_physician_sanitize_google_fonts( $doctor_physician_input, $doctor_physician_setting ) {
	$doctor_physician_choices = $doctor_physician_setting->manager->get_control( $doctor_physician_setting->id )->choices;
	return ( array_key_exists( $doctor_physician_input, $doctor_physician_choices ) ? $doctor_physician_input : $doctor_physician_setting->default );
}

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

function doctor_physician_sanitize_image( $doctor_physician_image, $doctor_physician_setting ) {
	/*
	* Array of valid image file types.
	*
	* The array includes image mime types that are included in wp_get_mime_types()
	*/
	$mimes = array(
		'jpg|jpeg|jpe' => 'image/jpeg',
		'gif'          => 'image/gif',
		'png'          => 'image/png',
		'bmp'          => 'image/bmp',
		'tif|tiff'     => 'image/tiff',
		'ico'          => 'image/x-icon',
		'svg'          => 'image/svg+xml',
	);
	// Return an array with file extension and mime_type.
	$file = wp_check_filetype( $doctor_physician_image, $mimes );
	// If $doctor_physician_image has a valid mime_type, return it; otherwise, return the default.
	return ( $file['ext'] ? $doctor_physician_image : $doctor_physician_setting->default );
}


function doctor_physician_sanitize_choices( $doctor_physician_input, $doctor_physician_setting ) {
    global $wp_customize; 
    $control = $wp_customize->get_control( $doctor_physician_setting->id ); 
    if ( array_key_exists( $doctor_physician_input, $control->choices ) ) {
        return $doctor_physician_input;
    } else {
        return $doctor_physician_setting->default;
    }
}

function doctor_physician_sanitize_range_value( $doctor_physician_number, $doctor_physician_setting ) {

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

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

	// Get minimum number in the range.
	$doctor_physician_min = ( isset( $doctor_physician_atts['min'] ) ? $doctor_physician_atts['min'] : $doctor_physician_number );

	// Get maximum number in the range.
	$doctor_physician_max = ( isset( $doctor_physician_atts['max'] ) ? $doctor_physician_atts['max'] : $doctor_physician_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $doctor_physician_min <= $doctor_physician_number && $doctor_physician_number <= $doctor_physician_max && is_int( $doctor_physician_number / $doctor_physician_step ) ? $doctor_physician_number : $doctor_physician_setting->default );
}