<?php

function resort_motel_sanitize_select( $resort_motel_input, $resort_motel_setting ) {
	$resort_motel_input = sanitize_key( $resort_motel_input );
	$resort_motel_choices = $resort_motel_setting->manager->get_control( $resort_motel_setting->id )->choices;
	return ( array_key_exists( $resort_motel_input, $resort_motel_choices ) ? $resort_motel_input : $resort_motel_setting->default );
}

function resort_motel_sanitize_switch( $resort_motel_input ) {
	if ( true === $resort_motel_input ) {
		return true;
	} else {
		return false;
	}
}

function resort_motel_sanitize_google_fonts( $resort_motel_input, $resort_motel_setting ) {
	$resort_motel_choices = $resort_motel_setting->manager->get_control( $resort_motel_setting->id )->choices;
	return ( array_key_exists( $resort_motel_input, $resort_motel_choices ) ? $resort_motel_input : $resort_motel_setting->default );
}


/**
 * Sanitize HTML input.
 *
 * @param string $resort_motel_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function resort_motel_sanitize_html( $resort_motel_input ) {
    return wp_kses_post( $resort_motel_input );
}

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

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

function resort_motel_sanitize_choices( $resort_motel_input, $resort_motel_setting ) {
	global $wp_customize; 
	$resort_motel_control = $wp_customize->get_control( $resort_motel_setting->id ); 
	if ( array_key_exists( $resort_motel_input, $resort_motel_control->choices ) ) {
		return $resort_motel_input;
	} else {
		return $resort_motel_setting->default;
	}
}

function resort_motel_sanitize_range_value( $resort_motel_number, $resort_motel_setting ) {

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

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

	// Get minimum number in the range.
	$resort_motel_min = ( isset( $resort_motel_atts['min'] ) ? $resort_motel_atts['min'] : $resort_motel_number );

	// Get maximum number in the range.
	$resort_motel_max = ( isset( $resort_motel_atts['max'] ) ? $resort_motel_atts['max'] : $resort_motel_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $resort_motel_min <= $resort_motel_number && $resort_motel_number <= $resort_motel_max && is_int( $resort_motel_number / $resort_motel_step ) ? $resort_motel_number : $resort_motel_setting->default );
}