<?php
function aster_portfolio_sanitize_select( $aster_portfolio_input, $aster_portfolio_setting ) {
	$aster_portfolio_input = sanitize_key( $aster_portfolio_input );
	$aster_portfolio_choices = $aster_portfolio_setting->manager->get_control( $aster_portfolio_setting->id )->choices;
	return ( array_key_exists( $aster_portfolio_input, $aster_portfolio_choices ) ? $aster_portfolio_input : $aster_portfolio_setting->default );
}

function aster_portfolio_sanitize_switch( $aster_portfolio_input ) {
	if ( true === $aster_portfolio_input ) {
		return true;
	} else {
		return false;
	}
}

function aster_portfolio_sanitize_google_fonts( $aster_portfolio_input, $aster_portfolio_setting ) {
	$aster_portfolio_choices = $aster_portfolio_setting->manager->get_control( $aster_portfolio_setting->id )->choices;
	return ( array_key_exists( $aster_portfolio_input, $aster_portfolio_choices ) ? $aster_portfolio_input : $aster_portfolio_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $aster_portfolio_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function aster_portfolio_sanitize_html( $aster_portfolio_input ) {
    return wp_kses_post( $aster_portfolio_input );
}

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

function aster_portfolio_sanitize_choices( $aster_portfolio_input, $aster_portfolio_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $aster_portfolio_setting->id ); 
	if ( array_key_exists( $aster_portfolio_input, $control->choices ) ) {
		return $aster_portfolio_input;
	} else {
		return $aster_portfolio_setting->default;
	}
}

function aster_portfolio_sanitize_range_value( $aster_portfolio_number, $aster_portfolio_setting ) {

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

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

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

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

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $aster_portfolio_min <= $aster_portfolio_number && $aster_portfolio_number <= $aster_portfolio_max && is_int( $aster_portfolio_number / $aster_portfolio_step ) ? $aster_portfolio_number : $aster_portfolio_setting->default );
}