<?php
function lawyer_consultant_firm_sanitize_select( $lawyer_consultant_firm_input, $lawyer_consultant_firm_setting ) {
	$lawyer_consultant_firm_input = sanitize_key( $lawyer_consultant_firm_input );
	$lawyer_consultant_firm_choices = $lawyer_consultant_firm_setting->manager->get_control( $lawyer_consultant_firm_setting->id )->choices;
	return ( array_key_exists( $lawyer_consultant_firm_input, $lawyer_consultant_firm_choices ) ? $lawyer_consultant_firm_input : $lawyer_consultant_firm_setting->default );
}

function lawyer_consultant_firm_sanitize_switch( $lawyer_consultant_firm_input ) {
	if ( true === $lawyer_consultant_firm_input ) {
		return true;
	} else {
		return false;
	}
}

function lawyer_consultant_firm_sanitize_google_fonts( $lawyer_consultant_firm_input, $lawyer_consultant_firm_setting ) {
	$lawyer_consultant_firm_choices = $lawyer_consultant_firm_setting->manager->get_control( $lawyer_consultant_firm_setting->id )->choices;
	return ( array_key_exists( $lawyer_consultant_firm_input, $lawyer_consultant_firm_choices ) ? $lawyer_consultant_firm_input : $lawyer_consultant_firm_setting->default );
}
/**
 * Sanitize HTML input.
 *
 * @param string $lawyer_consultant_firm_input HTML input to sanitize.
 * @return string Sanitized HTML.
 */
function lawyer_consultant_firm_sanitize_html( $lawyer_consultant_firm_input ) {
    return wp_kses_post( $lawyer_consultant_firm_input );
}

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

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

function lawyer_consultant_firm_sanitize_choices( $lawyer_consultant_firm_input, $lawyer_consultant_firm_setting ) {
	global $wp_customize; 
	$control = $wp_customize->get_control( $lawyer_consultant_firm_setting->id ); 
	if ( array_key_exists( $lawyer_consultant_firm_input, $control->choices ) ) {
		return $lawyer_consultant_firm_input;
	} else {
		return $lawyer_consultant_firm_setting->default;
	}
}

function lawyer_consultant_firm_sanitize_range_value( $lawyer_consultant_firm_number, $lawyer_consultant_firm_setting ) {

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

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

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

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

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

	// If the number is within the valid range, return it; otherwise, return the default.
	return ( $lawyer_consultant_firm_min <= $lawyer_consultant_firm_number && $lawyer_consultant_firm_number <= $lawyer_consultant_firm_max && is_int( $lawyer_consultant_firm_number / $lawyer_consultant_firm_step ) ? $lawyer_consultant_firm_number : $lawyer_consultant_firm_setting->default );
}