<?php

function dog_pet_house_sanitize_select( $dog_pet_house_input, $dog_pet_house_setting ) {
	$dog_pet_house_input = sanitize_key( $dog_pet_house_input );
	$dog_pet_house_choices = $dog_pet_house_setting->manager->get_control( $dog_pet_house_setting->id )->choices;
	return ( array_key_exists( $dog_pet_house_input, $dog_pet_house_choices ) ? $dog_pet_house_input : $dog_pet_house_setting->default );
}

function dog_pet_house_sanitize_switch( $dog_pet_house_input ) {
	if ( true === $dog_pet_house_input ) {
		return true;
	} else {
		return false;
	}
}

function dog_pet_house_sanitize_google_fonts( $dog_pet_house_input, $dog_pet_house_setting ) {
	$dog_pet_house_choices = $dog_pet_house_setting->manager->get_control( $dog_pet_house_setting->id )->choices;
	return ( array_key_exists( $dog_pet_house_input, $dog_pet_house_choices ) ? $dog_pet_house_input : $dog_pet_house_setting->default );
}

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

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

function dog_pet_house_sanitize_choices( $dog_pet_house_input, $dog_pet_house_setting ) {
    global $wp_customize; 
    $control = $wp_customize->get_control( $dog_pet_house_setting->id ); 
    if ( array_key_exists( $dog_pet_house_input, $control->choices ) ) {
        return $dog_pet_house_input;
    } else {
        return $dog_pet_house_setting->default;
    }
}

function dog_pet_house_sanitize_range_value( $number, $dog_pet_house_setting ) {

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

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

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

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

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $min <= $number && $number <= $max && is_int( $number / $step ) ? $number : $dog_pet_house_setting->default );
}