<?php
/**
 * The sidebar containing the main widget area
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Portfolio_One
 */

global $post;

$defaults 						= portfolio_one_customizer_defaults();
$post_meta 						= empty(portfolio_one_get_post_meta('portfolio_one_sidebar_layout')) ? 'default' : portfolio_one_get_post_meta('portfolio_one_sidebar_layout');
$portfolio_one_sidebar 				= portfolio_one_get_post_meta('portfolio_one_sidebar'); //meta sidebar area
$portfolio_one_post_sidebar_area  	= get_theme_mod( 'portfolio_one_post_sidebar_area', $defaults['portfolio_one_post_sidebar_area'] );
$portfolio_one_inner_single_sidebar = get_theme_mod( 'portfolio_one_inner_single_sidebar', $defaults['portfolio_one_inner_single_sidebar']);
$portfolio_one_blog_sidebar_area 	= get_theme_mod( 'portfolio_one_blog_sidebar_area', $defaults['portfolio_one_blog_sidebar_area']);
$portfolio_one_inner_blog_sidebar 	= get_theme_mod( 'portfolio_one_inner_blog_sidebar', $defaults['portfolio_one_inner_blog_sidebar']);
$post_sidebar 					= '';
$sidebar 						= '';

if( is_home() ){
	return;
}

if(!is_search() && is_single()){
	
	if( ($post_meta == 'default') && ($portfolio_one_inner_single_sidebar == 'sidebar-left' || $portfolio_one_inner_single_sidebar == 'sidebar-right') ) {

		$post_sidebar 	=  $portfolio_one_inner_single_sidebar;
		$sidebar 		= $portfolio_one_post_sidebar_area;

	}else if( $post_meta == 'sidebar-left' || 'sidebar-right' ){

		$post_sidebar 	=  $post_meta;
		$sidebar 		= $portfolio_one_sidebar;
	}else{
		$post_sidebar 	=  $post_meta;
		$sidebar 		= '';
	}

	
}

if(!is_search() && is_page() && !is_front_page()){

	if( ($post_meta == 'default') && ($portfolio_one_inner_single_sidebar == 'sidebar-left' || $portfolio_one_inner_single_sidebar == 'sidebar-right') ) {

		$post_sidebar 	=  $portfolio_one_inner_single_sidebar;
		$sidebar 		= $portfolio_one_post_sidebar_area;

	}else if( $post_meta == 'sidebar-left' || 'sidebar-right' ){

		$post_sidebar 	=  $post_meta;
		$sidebar 		= $portfolio_one_sidebar;
	}else{
		$post_sidebar 	=  $post_meta;
		$sidebar 		= '';
	}

}

if ( is_archive() || is_404() ) {
     $post_sidebar 	= $portfolio_one_inner_blog_sidebar;
     $sidebar 		= $portfolio_one_blog_sidebar_area;
}

if( is_search() ){
	$post_sidebar 	= $portfolio_one_inner_blog_sidebar;
	$sidebar 		= $portfolio_one_blog_sidebar_area;	
}



if( is_home() ){
	$post_sidebar 	= $portfolio_one_inner_blog_sidebar;
	$sidebar 		= $portfolio_one_blog_sidebar_area;
}


          

if ( ($post_sidebar ==  'sidebar-none')  ) {
	return;
}



if( ($post_sidebar == 'sidebar-left' || $post_sidebar == 'sidebar-right')  && is_active_sidebar($sidebar)){
	?>
		<aside class="widget-area secondary <?php echo esc_attr($post_sidebar);?>" role="complementary">
			<?php dynamic_sidebar( $sidebar ); ?>
		</aside><!-- #secondary -->
	<?php
}
