<?php

function roof_water_proofing_sanitize_select( $roof_water_proofing_input, $roof_water_proofing_setting ) {
	$roof_water_proofing_input = sanitize_key( $roof_water_proofing_input );
	$roof_water_proofing_choices = $roof_water_proofing_setting->manager->get_control( $roof_water_proofing_setting->id )->choices;
	return ( array_key_exists( $roof_water_proofing_input, $roof_water_proofing_choices ) ? $roof_water_proofing_input : $roof_water_proofing_setting->default );
}

function roof_water_proofing_sanitize_switch( $roof_water_proofing_input ) {
	if ( true === $roof_water_proofing_input ) {
		return true;
	} else {
		return false;
	}
}

function roof_water_proofing_sanitize_google_fonts( $roof_water_proofing_input, $roof_water_proofing_setting ) {
	$roof_water_proofing_choices = $roof_water_proofing_setting->manager->get_control( $roof_water_proofing_setting->id )->choices;
	return ( array_key_exists( $roof_water_proofing_input, $roof_water_proofing_choices ) ? $roof_water_proofing_input : $roof_water_proofing_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $roof_water_proofing_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function roof_water_proofing_sanitize_html( $roof_water_proofing_input ) {
    return wp_kses_post( $roof_water_proofing_input );
}

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

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

function roof_water_proofing_sanitize_choices( $roof_water_proofing_input, $roof_water_proofing_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $roof_water_proofing_setting->id ); 
	if ( array_key_exists( $roof_water_proofing_input, $control->choices ) ) {
		return $roof_water_proofing_input;
	} else {
		return $roof_water_proofing_setting->default;
	}
}

function roof_water_proofing_sanitize_range_value( $roof_water_proofing_number, $roof_water_proofing_setting ) {

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

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

	// Get minimum number in the range.
	$roof_water_proofing_min = ( isset( $roof_water_proofing_atts['min'] ) ? $roof_water_proofing_atts['min'] : $roof_water_proofing_number );

	// Get maximum number in the range.
	$roof_water_proofing_max = ( isset( $roof_water_proofing_atts['max'] ) ? $roof_water_proofing_atts['max'] : $roof_water_proofing_number );

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $roof_water_proofing_min <= $roof_water_proofing_number && $roof_water_proofing_number <= $roof_water_proofing_max && is_int( $roof_water_proofing_number / $roof_water_proofing_step ) ? $roof_water_proofing_number : $roof_water_proofing_setting->default );
}