<?php
/**
 * Theme customizer sanitization
 *
 * @package Organic Startup
 * @since Organic Startup 1.0
 */

/**
 * Sanitize Mulitple Selection.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_multi_select( $input ) {
	$valid = organic_startup_post_categories();

	foreach ( $input as $value ) {
		if ( ! array_key_exists( $value, $valid ) ) {
			return;
		}
	}

	return $input;
}

/**
 * Sanitize Categories.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_categories( $input, $setting ) {
	$input = absint( $input );
	return is_string( get_the_category_by_ID( $input ) ) ? $input : $setting->default;
}

/**
 * Sanitize Pages.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_pages( $input ) {
	$pages = get_all_page_ids();

	if ( in_array( $input, $pages, true ) ) {
			return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Slideshow Transition Interval.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_transition_interval( $input ) {
	$valid = array(
		'2000' 		=> esc_html__( '2 Seconds', 'organic-startup' ),
		'4000' 		=> esc_html__( '4 Seconds', 'organic-startup' ),
		'6000' 		=> esc_html__( '6 Seconds', 'organic-startup' ),
		'8000' 		=> esc_html__( '8 Seconds', 'organic-startup' ),
		'10000' 	=> esc_html__( '10 Seconds', 'organic-startup' ),
		'12000' 	=> esc_html__( '12 Seconds', 'organic-startup' ),
		'20000' 	=> esc_html__( '20 Seconds', 'organic-startup' ),
		'30000' 	=> esc_html__( '30 Seconds', 'organic-startup' ),
		'60000' 	=> esc_html__( '1 Minute', 'organic-startup' ),
		'999999999'	=> esc_html__( 'Hold Frame', 'organic-startup' ),
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Slideshow Transition Style.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_transition_style( $input ) {
	$valid = array(
		'fade' 		=> esc_html__( 'Fade', 'organic-startup' ),
		'slide' 	=> esc_html__( 'Slide', 'organic-startup' ),
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Columns.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_columns( $input ) {
	$valid = array(
		'one' 		=> esc_html__( 'One Column', 'organic-startup' ),
		'two' 		=> esc_html__( 'Two Columns', 'organic-startup' ),
		'three' 	=> esc_html__( 'Three Columns', 'organic-startup' ),
		'four' 	=> esc_html__( 'Four Columns', 'organic-startup' ),
		'five' 	=> esc_html__( 'Five Columns', 'organic-startup' ),
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Alignment.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_align( $input ) {
	$valid = array(
		'left'   => esc_html__( 'Left Align', 'organic-startup' ),
		'center' => esc_html__( 'Center Align', 'organic-startup' ),
		'right'  => esc_html__( 'Right Align', 'organic-startup' ),
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Position.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_position( $input ) {
	$valid = array(
		'top'    => esc_html__( 'Top Position', 'organic-startup' ),
		'left'   => esc_html__( 'Left Position', 'organic-startup' ),
		'right'  => esc_html__( 'Right Position', 'organic-startup' ),
		'bottom' => esc_html__( 'Bottom Position', 'organic-startup' ),
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Colors.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_title_color( $input ) {
	$valid = array(
		'black' => esc_html__( 'Black', 'organic-startup' ),
		'white' => esc_html__( 'White', 'organic-startup' ),
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}

/**
 * Sanitize Checkboxes.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_checkbox( $input ) {
	if ( 1 == $input ) {
		return 1;
	} else {
		return '';
	}
}

/**
 * Sanitize Text Input.
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_text( $input ) {
	return wp_kses_post( force_balance_tags( $input ) );
}

/**
 * Sanitize Font Weights
 *
 * @param array $input Sanitizes user input.
 * @return array
 */
function organic_startup_sanitize_font_weight( $input ) {
	$font_weights = array(
		'normal',
		'bold',
		'lighter',
	);

	if ( in_array( $input, $font_weights, true ) ) {
		return $input;
	} else {
		return '';
	}
}
