<?php
/**
 * Contains all theme specific functions.
 */

/**
 * Adds custom classes to the array of body classes.
 */
function igaa_body_classes( $classes ) {
	// Adds a class of group-blog to blogs with more than 1 published author.
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
    
    return $classes;
}
add_filter( 'body_class', 'igaa_body_classes' );


if ( ! function_exists( 'igaa_display_page_header' ) ) :
/**
 * Displays page header depends on page template.
 */
function igaa_display_page_header() {

    if ( is_archive() ) {
        the_archive_title();
        the_archive_description( '<div class="taxonomy-description uk-text-center-small">', '</div>' );
    } elseif ( is_search() ) {
        printf( esc_html__( 'Search Results for: %s', 'igaa' ), '<span>' . get_search_query() . '</span>' ); 
    } else {
        single_post_title(); 
    }
}
endif;

if ( ! function_exists( 'igaa_menu_class' ) ) :
/**
 * Displays classes for the main menu navbar.
 */
function igaa_menu_class( $class = '' ) {
	echo 'class="' . join( ' ', get_igaa_menu_class( $class ) ) . '"';
}
endif;

if ( ! function_exists( 'get_igaa_menu_class' ) ) :
/**
 * Retrieve classes for the main menu element as an array.
*/
function get_igaa_menu_class( $class = '' ) {
	
    $classes = array();

	if ( is_page_template( 'page-templates/builder.php' ) && true == get_theme_mod( 'igaa_enable_navbar_transparency', false ) ) {
		$classes[] = 'main-navbar main-navbar-transparent';
    } else {
        $classes[] = 'main-navbar';
    }

if ( !empty($class) ) {
		if ( !is_array( $class ) )
			$class = preg_split('#\s+#', $class);
		$classes = array_merge($classes, $class);
	}

	$classes = array_map('esc_attr', $classes);

	return apply_filters('get_igaa_menu_class', $classes, $class);
}
endif;

if ( ! function_exists( 'igaa_container_class' ) ) :
/**
 * Displays classes for the main container.
 */
function igaa_container_class( $class = '' ) {
	echo 'class="' . join( ' ', get_igaa_container_class( $class ) ) . '"';
}
endif;

if ( ! function_exists( 'get_igaa_container_class' ) ) :
/**
 * Retrieve classes for the main container as an array.
 */
function get_igaa_container_class( $class = '' ) {
	
    $classes = array();

	if ( ! is_page_template( 'page-templates/builder.php' ) )
		$classes[] = 'uk-container';
    
if ( !empty($class) ) {
		if ( !is_array( $class ) )
			$class = preg_split('#\s+#', $class);
		$classes = array_merge($classes, $class);
	}

	$classes = array_map('esc_attr', $classes);

	return apply_filters('get_igaa_container_class', $classes, $class);
}
endif;

if ( ! function_exists( 'igaa_animations' ) ) :
/**
 * Blog content entry animations depend on Customizer settings.
 */
function igaa_animations() {
    $igaa_animations_type = array('fade', 'scale-up', 'scale-down', 'slide-top', 'slide-bottom', 'slide-left', 'slide-right');
    $igaa_animations_value = get_theme_mod( 'igaa_entry_content_animations' );
   
    if ( $igaa_animations_value == 'scaleup' ) {
        echo  $igaa_animations_type[1];
    } elseif ( $igaa_animations_value == 'scaledown' ) {
        echo  $igaa_animations_type[2];
    } elseif ( $igaa_animations_value == 'slidetop' ) {
        echo  $igaa_animations_type[3];
    } elseif ( $igaa_animations_value == 'slidebottom' ) {
        echo  $igaa_animations_type[4];
    } elseif ( $igaa_animations_value == 'slideleft' ) {
        echo  $igaa_animations_type[5];
    } elseif ( $igaa_animations_value == 'slideright' ) {
        echo  $igaa_animations_type[6];
    } else {
        echo  $igaa_animations_type[0];
    }
    
}
endif;

if ( ! function_exists( 'igaa_sidebar_position_class' ) ) :
/**
 * Displays classes for the sidebar position depends on Customizer settings.
 */
function igaa_sidebar_position_class( $class = '' ) {
	echo 'class="' . join( ' ', get_igaa_sidebar_position_class( $class ) ) . '"';
}
endif;

if ( ! function_exists( 'get_igaa_sidebar_position_class' ) ) :
/**
 * Retrieve classes for the sidebar position as an array.
*/
function get_igaa_sidebar_position_class( $class = '' ) {
	
    $classes = array();
    $igaa_sidebar_position_value = get_theme_mod( 'igaa_sidebar_position' );

	if ( is_home() && $igaa_sidebar_position_value == 'left' ) {
		$classes[] = 'widget-area uk-width-medium-1-4 uk-pull-3-4 uk-margin-large-top';
    
    } elseif ( is_home() && $igaa_sidebar_position_value == 'none' ) {
        $classes[] = 'uk-hidden';
    
    } else {
        $classes[] = 'widget-area uk-width-medium-1-4 uk-margin-large-top';
    }
    
if ( !empty($class) ) {
		if ( !is_array( $class ) )
			$class = preg_split('#\s+#', $class);
		$classes = array_merge($classes, $class);
	}

	$classes = array_map('esc_attr', $classes);

	return apply_filters('get_igaa_sidebar_position_class', $classes, $class);
}
endif;

if ( ! function_exists( 'igaa_content_area_class' ) ) :
/**
 * Displays classes for the content area depends on sidebar position.
 */
function igaa_content_area_class( $class = '' ) {
	echo 'class="' . join( ' ', get_igaa_content_area_class( $class ) ) . '"';
}
endif;

if ( ! function_exists( 'get_igaa_content_area_class' ) ) :
/**
 * Retrieve classes for content area as an array.
*/
function get_igaa_content_area_class( $class = '' ) {
	
    $classes = array();
    $igaa_sidebar_position_value = get_theme_mod( 'igaa_sidebar_position' );

	if ( is_home() && $igaa_sidebar_position_value == 'left' ) {
		$classes[] = 'uk-width-medium-3-4 uk-push-1-4';
    
    } elseif ( is_home() && $igaa_sidebar_position_value == 'none' ) {
        $classes[] = 'uk-width-medium-3-4 uk-container-center';
    
    } else {
        $classes[] = 'uk-width-medium-3-4';
    }
    
if ( !empty($class) ) {
		if ( !is_array( $class ) )
			$class = preg_split('#\s+#', $class);
		$classes = array_merge($classes, $class);
	}

	$classes = array_map('esc_attr', $classes);

	return apply_filters('get_igaa_content_area_class', $classes, $class);
}
endif;