<?php

function florist_bouquet_sanitize_select( $florist_bouquet_input, $florist_bouquet_setting ) {
	$florist_bouquet_input = sanitize_key( $florist_bouquet_input );
	$florist_bouquet_choices = $florist_bouquet_setting->manager->get_control( $florist_bouquet_setting->id )->choices;
	return ( array_key_exists( $florist_bouquet_input, $florist_bouquet_choices ) ? $florist_bouquet_input : $florist_bouquet_setting->default );
}

function florist_bouquet_sanitize_switch( $florist_bouquet_input ) {
	if ( true === $florist_bouquet_input ) {
		return true;
	} else {
		return false;
	}
}

function florist_bouquet_sanitize_google_fonts( $florist_bouquet_input, $florist_bouquet_setting ) {
	$florist_bouquet_choices = $florist_bouquet_setting->manager->get_control( $florist_bouquet_setting->id )->choices;
	return ( array_key_exists( $florist_bouquet_input, $florist_bouquet_choices ) ? $florist_bouquet_input : $florist_bouquet_setting->default );
}

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

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

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

function florist_bouquet_sanitize_choices( $florist_bouquet_input, $florist_bouquet_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $florist_bouquet_setting->id ); 
	if ( array_key_exists( $florist_bouquet_input, $control->choices ) ) {
		return $florist_bouquet_input;
	} else {
		return $florist_bouquet_setting->default;
	}
}

function florist_bouquet_sanitize_range_value( $florist_bouquet_number, $florist_bouquet_setting ) {

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

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

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

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

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $florist_bouquet_min <= $florist_bouquet_number && $florist_bouquet_number <= $florist_bouquet_max && is_int( $florist_bouquet_number / $florist_bouquet_step ) ? $florist_bouquet_number : $florist_bouquet_setting->default );
}