<?php
/**
 * Content start - beginning of page content
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/* Theme and plugin configuration */
$enabled_plugins = array(
	'woocommerce' => class_exists( 'WooCommerce' ),
);

$content_classes = array( 'content' );

/** Buttons type */
$buttons_type      = get_theme_mod( 'multi_buttons_type', MULTIMAGAZINE_BUTTONS_TYPE );
$content_classes[] = 'btn-type-' . $buttons_type;

if ( 'gradient' === $buttons_type || 'flat' === $buttons_type ) {
	$buttons_animation = get_theme_mod( 'multi_button_animation', MULTIMAGAZINE_BUTTON_ANIMATION );
	if ( ! empty( $buttons_animation ) && 'fade' !== $buttons_animation ) {
		$content_classes[] = 'animated-buttons-' . $buttons_animation;
	}
}

/** Labels as placeholders */
$label_position = get_theme_mod( 'multi_form_label_position', MULTIMAGAZINE_FORM_LABEL_POSITION );
if ( ! empty( $label_position ) ) {
	$content_classes[] = 'label-pos-' . $label_position;
}

/** Getting the sidebar position for current page type */
global $multimagazine_sidebar_pos_global;
$multimagazine_sidebar_pos_global = 'right';
$multimagazine_sidebar_position   = '';
if ( is_search() ) {
	$multimagazine_sidebar_pos_global = get_theme_mod( 'multi_sidebar_pos_search', MULTIMAGAZINE_SIDEBAR_POS_SEARCH );

	$search_layout = absint( get_theme_mod( 'multi_search_results_layout', MULTIMAGAZINE_SEARCH_RESULTS_LAYOUT ) );
	if ( in_array( $search_layout, array( 1, 4, 5, 6 ), true ) ) {
		$multimagazine_sidebar_pos_global = 'off';
	}
} elseif ( is_single() ) {
	$multimagazine_sidebar_pos_global = get_theme_mod( 'multi_sidebar_pos_post', MULTIMAGAZINE_SIDEBAR_POS_POST );

} elseif ( is_page() ) {
	$multimagazine_sidebar_pos_global = get_theme_mod( 'multi_sidebar_pos_page', MULTIMAGAZINE_SIDEBAR_POS_PAGE );

} elseif ( is_archive() ) {
	$multimagazine_sidebar_pos_global = get_theme_mod( 'multi_sidebar_pos_archive', MULTIMAGAZINE_SIDEBAR_POS_ARCHIVE );

	$archive_layout       = absint( get_theme_mod( 'multi_post_list_layout', MULTIMAGAZINE_POST_LIST_LAYOUT ) );
	$layouts_with_sidebar = array( 0, 2, 3, 7 );

	if ( in_array( $archive_layout, $layouts_with_sidebar, true ) ) {
		$multimagazine_sidebar_position = $multimagazine_sidebar_pos_global;
	} else {
		$multimagazine_sidebar_position = 'off';
	}
} elseif ( is_home() ) {
	$multimagazine_sidebar_pos_global = get_theme_mod( 'multi_sidebar_pos_blog', MULTIMAGAZINE_SIDEBAR_POS_BLOG );
	$multimagazine_layout             = absint( get_theme_mod( 'multi_post_list_layout', MULTIMAGAZINE_POST_LIST_LAYOUT ) );
	$no_sidebar               = in_array( $multimagazine_layout, array( 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16 ), true );
	if ( $no_sidebar ) {
		$multimagazine_sidebar_pos_global = 'off';
	}
}

if ( ! is_search() && ! is_404() && ! is_archive() && ! is_home() ) {
	global $multimagazine_current_page_id;
	$multimagazine_current_page_id  = get_the_id();
	$multimagazine_sidebar_position = get_post_meta( $multimagazine_current_page_id, 'multi_sidebar_position', true );
	if ( empty( $multimagazine_sidebar_position ) || 'default' === $multimagazine_sidebar_position ) {
		$multimagazine_sidebar_position = $multimagazine_sidebar_pos_global;
	}
	if ( $enabled_plugins['woocommerce'] && is_product() ) {
		$multimagazine_sidebar_position = get_theme_mod( 'multi_sidebar_pos_wc_product', MULTIMAGAZINE_SIDEBAR_POS_WC_PRODUCT );
	}
} elseif ( ! is_archive() ) {
	$multimagazine_sidebar_position = $multimagazine_sidebar_pos_global;
}

if ( $enabled_plugins['woocommerce'] ) {
	if ( is_shop() ) {
		$multimagazine_sidebar_position = get_theme_mod( 'multi_sidebar_pos_wc_archive', MULTIMAGAZINE_SIDEBAR_POS_WC_ARCHIVE );
	} elseif ( is_product_category() ) {
		$multimagazine_sidebar_position = get_theme_mod( 'multi_sidebar_pos_wc_category', MULTIMAGAZINE_SIDEBAR_POS_WC_CATEGORY );
	} elseif ( is_product() ) {
		$multimagazine_sidebar_position = get_theme_mod( 'multi_sidebar_pos_wc_product', MULTIMAGAZINE_SIDEBAR_POS_WC_PRODUCT );
	}
}

$templates_no_sidebar = array(
	'post-list-masonry.php',
	'post-list-masonry-3.php',
	'post-list-full.php',
	'post-list-modern-2columns.php',
	'post-list-modern-3columns.php',
	'post-list-modern-fullwidth.php',
	'post-list-2columns.php',
	'post-list-3columns.php',
	'post-list-modern-mix.php',
	'post-list-trendy-mix.php',
	'post-list-fresh-mix.php',
	'portfolio-fullwidth4.php',
	'portfolio-metro-fullwidth.php',
);

if ( is_page_template( $templates_no_sidebar ) ) {
	$multimagazine_sidebar_position = 'off';
} elseif ( is_page_template( 'portfolio.php' ) ) {
	$portfolio_layout = get_theme_mod( 'multi_portfolio_layout', MULTIMAGAZINE_PORTFOLIO_LAYOUT );
	if ( empty( $portfolio_layout ) ) {
		$portfolio_layout = 'four-columns';
	}
	if ( in_array( $portfolio_layout, array( 'four-columns-fullwidth', 'metro-fullwidth', 'metro' ), true ) ) {
		$multimagazine_sidebar_position = 'off';
	}
} elseif ( is_tax( 'project-categories' ) || is_post_type_archive( 'project' ) ) {
	$multimagazine_sidebar_position = 'off';
}

$is_cart     = get_the_ID() === absint( get_option( 'woocommerce_cart_page_id' ) );
$is_checkout = get_the_ID() === absint( get_option( 'woocommerce_checkout_page_id' ) );
$is_thanks   = get_the_ID() === absint( get_option( 'woocommerce_thanks_page_id' ) );

if ( $is_cart || $is_checkout || $is_thanks ) {
	$multimagazine_sidebar_position = 'no';
}

switch ( $multimagazine_sidebar_position ) {
	case 'left':
		$content_classes[] = 'has-sidebar reverse';
		break;
	case 'off':
	case 'no':
		$content_classes[] = 'no-sidebar';
		break;
	default:
		$content_classes[] = 'has-sidebar';
		break;
}

if ( is_singular() ) {
	get_template_part( 'template-parts/sticky-post-nav' );
}

$content_classes[] = get_theme_mod( 'multi_fancy_borders', MULTIMAGAZINE_FANCY_BORDERS ) ? 'fancy-borders' : '';
$layout_type       = get_theme_mod( 'multi_layout_type', MULTIMAGAZINE_LAYOUT_TYPE );
$fixed_footer      = get_theme_mod( 'multi_fixed_footer', MULTIMAGAZINE_FIXED_FOOTER );

if ( 'wide' === $layout_type && $fixed_footer ) :
	?>
	<div class="content-wrapper">
	<?php
endif;
?>
<div class="<?php echo esc_attr( implode( ' ', $content_classes ) ); ?>" id="site-content">
