<?php

function social_blog_sanitize_select( $social_blog_input, $social_blog_setting ) {
	$social_blog_input = sanitize_key( $social_blog_input );
	$social_blog_choices = $social_blog_setting->manager->get_control( $social_blog_setting->id )->choices;
	return ( array_key_exists( $social_blog_input, $social_blog_choices ) ? $social_blog_input : $social_blog_setting->default );
}

function social_blog_sanitize_switch( $social_blog_input ) {
	if ( true === $social_blog_input ) {
		return true;
	} else {
		return false;
	}
}

function social_blog_sanitize_google_fonts( $social_blog_input, $social_blog_setting ) {
	$social_blog_choices = $social_blog_setting->manager->get_control( $social_blog_setting->id )->choices;
	return ( array_key_exists( $social_blog_input, $social_blog_choices ) ? $social_blog_input : $social_blog_setting->default );
}

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

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

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

function social_blog_sanitize_choices( $social_blog_input, $social_blog_setting ) {
	global $wp_customize; 
	$social_blog_control = $wp_customize->get_control( $social_blog_setting->id ); 
	if ( array_key_exists( $social_blog_input, $social_blog_control->choices ) ) {
		return $social_blog_input;
	} else {
		return $social_blog_setting->default;
	}
}

function social_blog_sanitize_range_value( $social_blog_number, $social_blog_setting ) {

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

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

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

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

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $social_blog_min <= $social_blog_number && $social_blog_number <= $social_blog_max && is_int( $social_blog_number / $social_blog_step ) ? $social_blog_number : $social_blog_setting->default );
}