<?php
/**
 * The template for displaying product content in the single-product.php template
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-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://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.6.0
 */

defined( 'ABSPATH' ) || exit;

global $product;

$tdl_options = woodstock_global_var();

//woocommerce_before_single_product_summary
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
	
add_action( 'woocommerce_before_single_product_summary_product_images', 'woocommerce_show_product_images', 20 );

//custom actions
add_action( 'woocommerce_product_summary_thumbnails', 'woocommerce_show_product_thumbnails', 20 );

//woocommerce_single_product_summary
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
// remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

add_action( 'woocommerce_single_product_summary_single_title', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary_single_rating', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary_single_price', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary_single_excerpt', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary_single_meta', 'woocommerce_template_single_meta', 40 );
// add_action( 'woocommerce_single_product_summary_single_add_to_cart', 'woocommerce_template_single_add_to_cart', 30 );

//woocommerce_after_single_product_summary
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
	
add_action( 'woocommerce_after_single_product_summary_data_tabs', 'woocommerce_output_product_data_tabs', 10 );

$product_sidebar = (!empty($tdl_options['tdl_product_sidebar'])) ? $tdl_options['tdl_product_sidebar'] : '3'; 

if ($product_sidebar == 1) {$product_sidebar = 'left-sidebar';} else if ($product_sidebar == 2) {$product_sidebar = 'right-sidebar';} else {$product_sidebar = 'full-width';};
if (isset($_GET["product_sidebar"])) { $product_sidebar = $_GET["product_sidebar"]; }
?>
<style>
.woocommerce div.product form.cart, .woocommerce #content div.product form.cart, .woocommerce-page div.product form.cart, .woocommerce-page #content div.product form.cart {
	border: none;
}

	@media screen and (max-width: 372px) {
		.products .product_after_shop_loop_switcher a.button, .products .category-price-grid-list a.button {
			padding: 0rem 0.5375rem !important;
		}
	}
	.woocommerce div.product form.cart tr, .woocommerce-page div.product form.cart tr, .woocommerce #content div.product form.cart tr, .woocommerce-page #content div.product form.cart tr, .single_variation_wrap { float: right; }
	.woocommerce div.product form.cart tr td.label, .woocommerce #content div.product form.cart tr td.label, .woocommerce-page div.product form.cart tr td.label, .woocommerce-page #content div.product form.cart tr td.label {width:35%;}
	.single-product-infos {width:50%; float:right;}
	@media screen and (max-width: 992px) {
		.product-name-desktop {
			display:none !important;
		}
		.product-name-mobile {
			font-size: 20px !important;
    		text-align: center;
		}
	}
	@media screen and (min-width: 992px) {
		.product-name-mobile {
			display:none !important;
		}
		.product-name-desktop {
			font-size: 27px !important
		}
	}
	.cwginstock-subscribe-form {
		width: 50%;
    	float: right;
	}
	#button_offcanvas_sidebar_left_kategorie {
		text-align:center;
		background-color: green !important;
		color: #fff;
		font-size:18px;
		font-weight:500 !important;
		padding:5px 10px;
	}
    #button_offcanvas_sidebar_left_kategorie .mobile-menu-icon {
		display: inline-block;
    	vertical-align: middle;
    	line-height: 30px;
   		margin-right: 5px;
	}
	#button_offcanvas_sidebar_left_kategorie .mobile-menu-icon:before {
		color: #fff;
    	font-size: 24px;
		font-family: "Woodstock";
    	content: "\e610";
	}
	@media screen and (min-width: 992px) {
		#button_offcanvas_sidebar_left_kategorie {
			display:none;
		}
	}
	.variantes {
		margin-top:75px;
	}
	.woocommerce div.product form.cart .variations label {
		margin-right:10px;
	}
	.item-variant .item-wrap {
		width: 40%;
		display:inline-block;
		padding-left: 10px;
		flex-flow: column;
	}
	.item-variant .item-price {
		margin-bottom: 10px;
    	margin-top: 10px;
	}
	.item-variant .item-image {
		display:inline;
		width:50%;
	}
	.item-variant .item-purchase {
		padding-left: 10px;
    	display: inline-block;
    	position: relative;
    	top: -50px;
	}
	.item-variant .item-purchase > div {
		padding-left:15px;
	}
	.item-variant .item-purchase > div:first-child {
		padding-left:0px;
	}
	.price-value {
		font-size: 24px;
    	font-weight: 600;
	}
	.availability-value {
		font-size:18px;
		text-transform: uppercase;
		font-weight: 500;
	}
	.item-availability {
		margin-top:5px;
		margin-bottom:5px;
	}
	.item-image img {
		position: relative;
    	top: -35px;
	}
	.item-info {
		width: 10%;
    	display: inline-block;
	}
	.availability-label { font-size: 14px; }
	.item-name { font-size: 20px; }
	@media screen and (max-width:1366px) {
		.item-variant .item-purchase {
			padding-left: 30px;
    		display: inline-block;
    		position: relative;
    		top: -55px;
		}
		.item-variant .item-wrap {
			width: 30%;
		}
		.item-image img {
			top: -50px;
		}
	}
	@media screen and (max-width: 1280px) {
		.item-variant .item-wrap { 
			width: 25%;
		}
	}
	@media screen and (max-width: 1230px) {
		.item-variant .item-wrap {
			width:20%;
		}
	}
	@media screen and (max-width: 1024px) {
		.item-variant .item-wrap {
			width:25%;
		}
	}
	@media screen and (max-width: 992px) {
		.item-variant {
			margin: auto;
			width: 50%;
			padding: 10px;
		}
		.variable-product-variant-image {
			height: 120px!important;
		}
		.item-variant .item-wrap {
    		width: 40%;
		}
	}
	@media screen and (max-width: 768px) {
		.item-variant .item-wrap {
			width:25%;
		}
		.item-image img {
			top:-70px;
		}
		.variable-product-variant-image {
			height: 150px!important;
		}
		.item-variant .item-purchase {
			padding-left: 40px;
    		display: inline-block;
    		position: relative;
    		top: -55px;
		}
	}
	@media screen and (max-width: 580px) {
		.item-variant {
			width: 100%;
		}
	}
	@media screen and (max-width:480px) {
		.item-variant .item-wrap {
			width:20%;
		}
		.variable-product-variant-image {
    		height: 120px!important;
		}
		.item-image img {
    		top: -60px;
		}
		.variantes {
			margin-top:25px;
		}
	}
	@media screen and (max-width: 420px) {
		.item-variant .item-wrap {
			width: 30%;
		}
		.item-variant .item-purchase {
			padding-left:10px;
		}
	}
	@media screen and (max-width: 400px) {
		.item-variant .item-wrap {
			width: 30%;
		}
		.price-value {
			font-size:22px;
		}
	}
	@media screen and (max-width: 388px) {
		.price-value {
			font-size: 20px;
		}
		.item-variant .item-wrap {
			width:20%;
		}
		.item-variant .item-purchase {
			padding-left:40px;
		}
		.item-variant {
			margin: auto;
			width: 100%;
			padding: 10px;
		}
	}
	@media screen and (max-width: 360px) {
		.price-value { font-size: 18px;}
		.item-name{font-size: 18px;}
		.availability-value {font-size:16px;}
		.availability-label{font-size:14px;}
		.item-variant .item-wrap{width:15%;}
		.item-variant .item-purchase {
    		padding-left: 50px;
		}
	}
</style>

<div class="row">
	<div class="large-12 columns">
	<?php
		/**
		 * woocommerce_before_single_product hook.
		 *
		 * @hooked wc_print_notices - 10
		 */
		 do_action( 'woocommerce_before_single_product' );

		 if ( post_password_required() ) {
		 	echo get_the_password_form();
		 	return;
		 }
	?>
	</div>
</div>


<div id="product-<?php the_ID(); ?>" <?php wc_product_class( '', $product ); ?>>

	<?php if ( $product_sidebar != "full-width" ) : ?>
		<div class="single-product with-sidebar <?php echo esc_attr($product_sidebar); ?>">
			<div class="row">
				<?php if ( $shop_sidebar != "full-width" ) : ?>
						<?php if (is_active_sidebar( 'widgets-product-listing')) : ?>
							<!-- Shop Sidebar Button --> 
							<div id="button_offcanvas_sidebar_left_kategorie"><i class="mobile-menu-icon"></i> Kategorie</div>
						<?php endif; ?>
					<?php endif; ?> 
				
				<div class="xlarge-2 large-3 columns show-for-large-up sidebar-pos">
					<div class="shop_sidebar wpb_widgetised_column">
						<?php if ( is_active_sidebar( 'widgets-product-page-listing' ) ) { ?>
							<?php dynamic_sidebar( 'widgets-product-page-listing' ); ?>
						<?php } ?>					
					</div>
				</div><!--.columns-->	

				<div class="xlarge-10 large-9 columns content-pos">
						<?php if ((isset($tdl_options['tdl_shop_breadcrumb'])) && ($tdl_options['tdl_shop_breadcrumb'] == "1"))
								{
								// BREADCRUMBS
								echo woodstock_breadcrumbs();
								}?>
						<?php do_action( 'woocommerce_single_product_summary_single_title' ); ?>
						<div class="single-product-images with_sidebar">
						
							<?php the_title( '<h1 itemprop="name" class="product_title entry-title product-name-mobile">', '</h1>' ); ?>
							<?php				
								if ( (isset($tdl_options['tdl_catalog_mode'])) && ($tdl_options['tdl_catalog_mode'] == 0) ) {
									wc_get_template( 'loop/sale-flash.php' );
								}
								do_action( 'woocommerce_before_single_product_summary_product_images' );
								do_action( 'woocommerce_before_single_product_summary' );
							?>

							<div class="product_summary_thumbnails_wrapper with-sidebar">
								<div><?php do_action( 'woocommerce_product_summary_thumbnails' ); ?></div>
							</div><!-- .product_summary_thumbnails_wrapper-->
							
						</div>
						<?php
									$obj_id = get_queried_object_id();
									$current_url = get_permalink( $obj_id );
									?>
						<?php
						if ((isset($tdl_options['tdl_product_addtocart_ajax'])) && ($tdl_options['tdl_product_addtocart_ajax'] == "1")) {
							$addtocart_class = $tdl_options['tdl_header_ajax_loader'];
						}
						?>

						<!-- Product Content -->

						<div class="single-product-infos">
							<div class="product_infos <?php echo esc_attr($addtocart_class) ?>">						

							<?php 
							woodstock_share();
							?>
								
							<?php

								$shortexcerpt = wp_trim_words( $post->post_excerpt, $num_words = $tdl_options['tdl_product_description_number'], $more = '...' );

								do_action( 'woocommerce_single_product_summary_single_rating' );
								do_action( 'woocommerce_single_product_summary_single_price' );
                             
								$ean = get_post_meta( $product->get_id(), '_ean', true ); 
								if(!empty($ean)) { ?>
									<meta itemprop="gtin" content="<?php echo $ean; ?>">
							   <?php } ?>
								<meta itemprop="price" content="<?php echo $product->get_price(); ?>" />
    							<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" />
								<span itemprop="offers" itemscope="" itemtype="https://schema.org/Offer">
									<link itemprop="availability" href="https://schema.org/InStock">
									<meta itemprop="url" content="<?php echo $current_url; ?>">            
    								<meta itemprop="price" content="<?php echo $product->get_price(); ?>">
    								<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>">

    								<link itemprop="itemCondition" href="https://schema.org/NewCondition">

								</span>

								<?php if ( (isset($tdl_options['tdl_productpage_description'])) && ($tdl_options['tdl_productpage_description'] == 1) ) {
									echo force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( wpautop($post->post_excerpt) ), $num_words, $shortexcerpt ) ) );
								} else {
									do_action( 'woocommerce_single_product_summary_single_excerpt' );
								}								

								
								do_action( 'woocommerce_single_product_summary_single_add_to_cart' );
								do_action( 'woocommerce_single_product_summary' );
								echo '<br><br>Doručení do: <span style="color:green;font-weight:700;"> 2 </span><span style="color:green;">až 4 <span style="font-weight:700;">pracovních dnů</span></span>';

							?>

							</div>
						</div>


					<div class="clearfix"></div>

					<div class="summary-description">
						<?php
							do_action( 'woocommerce_single_product_summary_single_meta' );
							do_action( 'woocommerce_after_single_product_summary_data_tabs' );
							do_action( 'woocommerce_single_product_summary_single_sharing' );
						?>
					</div><!-- .columns -->


				</div><!--.columns-->

			</div><!--.row-->

					<div class="row">
						<div class="large-12 large-uncentered columns">
							<?php
								do_action( 'woocommerce_after_single_product_summary' );
							?>
							<div class="product_navigation">
								<?php woodstock_product_nav( 'nav-below' ); ?>
							</div>
						</div><!-- .columns -->
					</div><!-- .row -->
		</div><!--.single-product .with-sidebar-->
	<?php else : ?>
	<div itemscope itemtype="http://schema.org/Product">
		<div class="single-product without-sidebar">
			<div class="row">
				<div class="large-12 columns"><?php do_action( 'woocommerce_before_single_product' ); ?></div>
				
				<div class="large-6 columns obrazky-produktu content-pos">

						<div class="image-content">

								<div class="product_summary_thumbnails_wrapper without_sidebar">
									<div><?php do_action( 'woocommerce_product_summary_thumbnails' ); ?>&nbsp;</div>
								</div><!-- .columns -->	

								<div class="single-product-images without_sidebar">

									<?php				
										if ( (isset($tdl_options['tdl_catalog_mode'])) && ($tdl_options['tdl_catalog_mode'] == 0) ) {
											wc_get_template( 'loop/sale-flash.php' );
										}
										do_action( 'woocommerce_before_single_product_summary_product_images' );
									    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ), 'single-post-thumbnail' ); ?>
									    <meta itemprop="image" content="<?php echo $image[0]; ?>" />
										<?php do_action( 'woocommerce_before_single_product_summary' );
									?>

								</div>

						</div>
				</div>
						<!-- Product Content -->
<div class="large-6 columns info-produktu content-pos">
						<div class="single-product-infos">
							<div class="product_infos">						

							<?php 
							woodstock_share();

							if ((isset($tdl_options['tdl_shop_breadcrumb'])) && ($tdl_options['tdl_shop_breadcrumb'] == "1"))
								{
								// BREADCRUMBS
								echo woodstock_breadcrumbs();
								}
							?>
								
							<?php
								do_action( 'woocommerce_single_product_summary_single_title' );
								do_action( 'woocommerce_single_product_summary_single_rating' );
								do_action( 'woocommerce_single_product_summary_single_price' ); 
								$ean = get_post_meta( $product->get_id(), '_ean', true ); 
								if(!empty($ean)) { ?>
									<meta itemprop="gtin" content="<?php echo $ean; ?>">
							   <?php } 
								$content = get_the_content();
								$new_content = strval(substr($content, 0, 119));?>
								<meta itemprop="price" content="<?php echo $product->get_price(); ?>" />
    							<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" />
								<span itemprop="offers" itemscope="" itemtype="https://schema.org/Offer">
									<link itemprop="availability" href="https://schema.org/InStock">
									<?php
									$obj_id = get_queried_object_id();
									$current_url = get_permalink( $obj_id );
									?>
									<meta itemprop="url" content="<?php echo $current_url; ?>">            
    								<meta itemprop="price" content="<?php echo $product->get_price(); ?>">
    								<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>">

    								<link itemprop="itemCondition" href="https://schema.org/NewCondition">

								</span>
								<?php do_action( 'woocommerce_single_product_summary_single_excerpt' );
								do_action( 'woocommerce_single_product_summary_single_add_to_cart' );
								do_action( 'woocommerce_single_product_summary' );
								//echo $product->get_sku();
								echo '<br><br>Doručení do: <span style="color:green;font-weight:700;"> 2 </span><span style="color:green;">až 4 <span style="font-weight:700;">pracovních dnů</span></span>';
							?>
								
							</div>
						</div>

	</div>
				<div class="large-12 columns content-pos">

					<div class="clearfix"></div>

					<div class="summary-description">
						<?php
							do_action( 'woocommerce_single_product_summary_single_meta' );
							do_action( 'woocommerce_after_single_product_summary_data_tabs' );
							do_action( 'woocommerce_single_product_summary_single_sharing' );
						?>
					</div><!-- .columns -->


				</div><!--.columns-->

			</div><!--.row-->

					<div class="row">
						<div class="large-12 large-uncentered columns">
							<?php
								do_action( 'woocommerce_after_single_product_summary' );
							?>
							<div class="product_navigation">
								<?php woodstock_product_nav( 'nav-below' ); ?>
							</div>
						</div><!-- .columns -->
					</div><!-- .row -->
		</div>
		</div>
	<?php endif; ?>

	<meta itemprop="url" content="<?php the_permalink(); ?>" />

	<?php if ( $product_sidebar != "full-width" ) : ?>
		<?php if (is_active_sidebar( 'widgets-product-page-listing')) : ?>
				<div id="button_offcanvas_sidebar_left" style="display:none;"><i class="sidebar-icon"></i></div>
		<?php endif; ?>
	<?php endif; ?>

</div><!-- #product-<?php the_ID(); ?> -->


<?php do_action( 'woocommerce_after_single_product' ); ?>
