<?php
function events_and_celebrations_sanitize_select( $events_and_celebrations_input, $events_and_celebrations_setting ) {
	$events_and_celebrations_input = sanitize_key( $events_and_celebrations_input );
	$events_and_celebrations_choices = $events_and_celebrations_setting->manager->get_control( $events_and_celebrations_setting->id )->choices;
	return ( array_key_exists( $events_and_celebrations_input, $events_and_celebrations_choices ) ? $events_and_celebrations_input : $events_and_celebrations_setting->default );
}

function events_and_celebrations_sanitize_switch( $events_and_celebrations_input ) {
	if ( true === $events_and_celebrations_input ) {
		return true;
	} else {
		return false;
	}
}

function events_and_celebrations_sanitize_google_fonts( $events_and_celebrations_input, $events_and_celebrations_setting ) {
	$events_and_celebrations_choices = $events_and_celebrations_setting->manager->get_control( $events_and_celebrations_setting->id )->choices;
	return ( array_key_exists( $events_and_celebrations_input, $events_and_celebrations_choices ) ? $events_and_celebrations_input : $events_and_celebrations_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $events_and_celebrations_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function events_and_celebrations_sanitize_html( $events_and_celebrations_input ) {
    return wp_kses_post( $events_and_celebrations_input );
}

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

function events_and_celebrations_sanitize_choices( $events_and_celebrations_input, $events_and_celebrations_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $events_and_celebrations_setting->id ); 
	if ( array_key_exists( $events_and_celebrations_input, $control->choices ) ) {
		return $events_and_celebrations_input;
	} else {
		return $events_and_celebrations_setting->default;
	}
}

function events_and_celebrations_sanitize_range_value( $events_and_celebrations_number, $events_and_celebrations_setting ) {

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

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

	// Get minimum number in the range.
	$events_and_celebrations_min = ( isset( $events_and_celebrations_atts['min'] ) ? $events_and_celebrations_atts['min'] : $events_and_celebrations_number );

	// Get maximum number in the range.
	$events_and_celebrations_max = ( isset( $events_and_celebrations_atts['max'] ) ? $events_and_celebrations_atts['max'] : $events_and_celebrations_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $events_and_celebrations_min <= $events_and_celebrations_number && $events_and_celebrations_number <= $events_and_celebrations_max && is_int( $events_and_celebrations_number / $events_and_celebrations_step ) ? $events_and_celebrations_number : $events_and_celebrations_setting->default );
}