<?php
/**
 * Template Post Type: post
 *
 *  The Template for displaying all single products
 *
 *  This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
 *
 *  HOWEVER, on occasion WooCommerce will need to update template files and you
 *  (the theme developer) will need to copy the new files to your theme to
 *  maintain compatibility. We try to do this as little as possible, but it does
 *  happen. When this occurs the version of the template file will be bumped and
 *  the readme will list any important changes.
 *
 * @see         https://woocommerce.com/document/template-structure/
 * @version     1.6.4
 *
 * @package wpstream-theme
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}


get_header();

global $wpstream_plugin;
global $post;
$post_id = $post->ID;//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

if( function_exists('wc_get_product') ){
	$product = wc_get_product( $post_id );
}

$product_type 							 =	$product->get_type();
$current_user           				 =	wp_get_current_user();
$wpstream_product_details_page_sidebar   =	wpstream_theme_is_show_sidebar();
$wpstream_video_on_demand_show_chat      =	get_theme_mod( 'wpstream_video_on_demand_show_chat' );

$show_comments_section       = get_theme_mod( 'wpstream_product_show_comments_section', true );
$show_related_products       = get_theme_mod( 'wpstream_product_show_related_products', true );

$gallery_class="";	
$product_info_class="";
if( $product_type ==='simple'){
	$product_info_class = " col-lg-3 ";
	$gallery_class = " ";
}

?>
    <section class="wpstream_section wpstream_featured_banner_vod wpstream-featured-player-wrapper <?php echo $product_type === 'simple' ? 'simple-product' : '' ?>">
        <div class="<?php echo esc_attr( wpstream_theme_container_class() ); ?>">
            <div class="row">
				<?php
				if ( $product && $product_type === 'simple') {
					?>
                    <?php
                        if ( get_post_meta( $post_id, '_thumbnail_id' ) || get_post_meta( $post_id, '_product_image_gallery' ) ) {
                    ?>
                    <div class="wpstream-simple-product-gallery-wrapper wp-stream-blog-content-extra-padding col-12 col-lg-9">
                        <div class="wpstream-simple-product-gallery-right col-12">
                            <?php
                            echo wpstream_theme_image_gallery( $post_id, 'full', 3 );
                            ?>
                        </div>
                    </div>
                    <?php } ?>
						<div class="product-info col-12 col-lg-3">
							<?php
								include get_template_directory() . '/template-parts/single/product-add-to-cart-section.php';
							?>
						</div>
					<?php
				} else {
					$display_title_area = true;

					if ($wpstream_plugin->main->wpstream_player->wpstream_check_if_player_can_dsplay_theme($post_id)) {
						wpstream_theme_display_player_wrapper($post_id);
					} else {
						$display_title_area = false;
						$poster_id = get_post_thumbnail_id($post_id);
						$poster_data = wp_get_attachment_image_src($poster_id, 'full');
						$poster_url = '';

						if (isset($poster_data[0])) {
							$poster_url = $poster_data[0];
						}

						echo '<div class="wpstream_player_wrapper wpstream_player_shortcode">';
						echo '<div class="wpstream_player_container">';

						echo '<div class="wpstream_video_poster_holder wpstream_hide_on_trailer" style="background-image:url(' . esc_attr($poster_url) . '"></div>';
						echo '<div class="wpstream_player_container_gradient wpstream_hide_on_play"></div>';
						include get_template_directory() . '/template-parts/single/product-add-to-cart-section.php';

						$wpstream_plugin->main->wpstream_player->wpstream_video_on_demand_player_only_trailer($post_id);

						echo '</div>';
						echo '</div>';
					}
				}
				?>
            </div>
        </div>
    </section>
    <section class="wpstream_section wp-stream-vod-content">
        <div class="<?php echo esc_attr( wpstream_theme_container_class() ); ?>">
			<?php if ( have_posts() ) : ?>
				<?php while ( have_posts() ) : ?>
					<?php the_post(); ?>

                    <div class="row">
						<?php if ( $wpstream_product_details_page_sidebar ) : ?>
                            <div class="col-12 col-lg-9 wp-stream-blog-content-extra-padding">
								<?php if ( 'wpstream_bundle' === $product_type ) : ?>
									<?php include get_template_directory() . '/template-parts/single/single-product-content-collection.php'; ?>
								<?php else : ?>

									<?php include get_template_directory() . '/template-parts/single/single-product-content.php'; ?>
								<?php endif; ?>
                            </div>

							<?php if ( $wpstream_product_details_page_sidebar ) : ?>
								<?php get_sidebar(); ?>
							<?php endif; ?>
						<?php else : ?>
                            <div class="col-12">
								<?php if ( 'wpstream_bundle' === $product_type ) : ?>
									<?php include get_template_directory() . '/template-parts/single/single-product-content-collection.php'; ?>
								<?php else : ?>
									<?php include get_template_directory() . '/template-parts/single/single-product-content.php'; ?>
								<?php endif; ?>
                            </div>
						<?php endif; ?>
                    </div>
                    <!-- /.row -->
				<?php endwhile; ?>

				<?php wp_reset_postdata(); ?>
			<?php else : ?>
                <p><?php esc_html_e( 'Sorry, no videos matched your criteria.', 'hello-wpstream' ); ?></p>
			<?php endif; ?>
        </div>
    </section>

<?php
if ( $show_related_products ){
	$wpstream_section_title = esc_html__( 'Related Products', 'hello-wpstream' );
	require get_template_directory() . '/template-parts/single/section/video-related-content.php';
}

get_footer();