<?php
/**
 * 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://docs.woocommerce.com/document/template-structure/
 * @package     WooCommerce\Templates
 * @version     1.6.4
 */

 ?>
 	<?php
	if (!defined("ABSPATH")) {
	  exit(); // Exit if accessed directly
	}
	global $product;
	
	/* General settings */
	$configurator_url = esc_attr(get_option("configurator_endpoint_setting"));
	$configurator_schema = esc_attr(get_option("configurator_scheme_setting"));
	$configurator_version = esc_attr(get_option("configurator_version_setting"));
	$configurator_cdn = esc_attr(get_option("configurator_cdn_setting"));
	$configurator_assets = esc_attr(get_option("configurator_assets_setting"));
	$configurator_language = esc_attr(get_option("configurator_language_setting"));
	$configurator_AREnabled = esc_attr(get_option("configurator_AREnabled_setting"));
	$configurator_standaloneFloors = esc_attr(get_option("configurator_standaloneFloors_setting"));
	$configurator_showAsConfigured = esc_attr(get_option("configurator_showAsConfigured_setting"));
	$configurator_camera = esc_attr(get_option("configurator_camera_setting"));
	$configurator_background = esc_attr(get_option("configurator_background_setting"));
	$configurator_gtm = esc_attr(get_option("configurator_gtm_setting"));
	$configurator_show3dwatermark = esc_attr(get_option("configurator_show3dwatermark_setting"));
	$configurator_showtagfilter = esc_attr(get_option("configurator_showtagfilter_setting"));
	$configurator_showzoombutton = esc_attr(get_option("configurator_showzoombutton_setting"));
	$configurator_showdimensions = esc_attr(get_option("configurator_showdimensions_setting"));  
	$configurator_showdownload = esc_attr(get_option("configurator_showdownload_setting"));
	/* Render settings */
	$configurator_useioneimages = esc_attr(get_option("configurator_use_ione_images_setting"));
	$configurator_userenders = esc_attr(get_option("configurator_use_renders_setting"));
	$configurator_renderhost = esc_attr(get_option("configurator_render_host_setting"));
	$configurator_renderport = esc_attr(get_option("configurator_render_port_setting"));
	$configurator_enviromentIntensity = esc_attr(get_option("configurator_render_environmentIntensity"));
	$configurator_render_imageWidth = esc_attr(get_option("configurator_render_imageWidth"));
	$configurator_render_imageHeight = esc_attr(get_option("configurator_render_imageHeight"));
	$configurator_render_iterations = esc_attr(get_option("configurator_render_iterations"));
	/* Layout settings */
	$configurator_layout = esc_attr(get_option("configurator_layout"));
	$configurator_printButton = esc_attr(get_option("configurator_showprint_button"));
	$configurator_printText = esc_attr(get_option("configurator_printtext_setting"));	
	$configurator_buttonsScene = esc_attr(get_option("configurator_colorbtn_threed"));
	$configurator_buttonsCta = esc_attr(get_option("configurator_colorbtn_cta"));
	$configurator_radiusCta = esc_attr(get_option("configurator_cta_radius"));
	$configurator_buttonsTextScene = esc_attr(get_option("configurator_colorbtntext_threed"));
	$configurator_buttonsTextCta = esc_attr(get_option("configurator_colorbtn_ctatext"));
	$configurator_headingColor = esc_attr(get_option("configurator_colorheading_config"));
	$configurator_labelsColor = esc_attr(get_option("configurator_colorlabel_config"));
	$configurator_textColor = esc_attr(get_option("configurator_colortext_config"));
	$configurator_btnRadius = esc_attr(get_option("configurator_button_radius"));
	$configurator_showName = esc_attr(get_option("configurator_showname_text"));
	$configurator_hideTotalPrice = esc_attr(get_option("configurator_hideprice_text"));
	$configurator_customCss = esc_attr(get_option("configurator_custom_css_setting"));
	/* Contact settings */
	$configurator_contactButton = esc_attr(get_option("configurator_enable_contact_form"));
	$configurator_contactText = esc_attr(get_option("configurator_contact_text_setting"));		

	/* Woocommerce settings */
	$woocommerce_enable_contact_form = esc_attr(get_option("woocommerce_enable_contact_form"));
	$woocommerce_scenewidth_canvas = esc_attr(get_option("woocommerce_scenewidth_canvas"));
	$woocommerce_enable_print_pdf = esc_attr(get_option("woocommerce_enable_print_pdf"));	
	
	/* Meta Product settings */
	$configurator_addToCart = $product->get_meta("_configurator_demo");
	$configurator_Only = $product->get_meta("_configurator_confirmation");

	wp_enqueue_style(
		"general_new",
		plugin_dir_url(__FILE__) . "public/css/general.css",
		1.1,
		"all"
	  );
	if ($woocommerce_enable_contact_form) {
	wp_enqueue_style(
		"contact",
		plugin_dir_url(__FILE__) . "public/css/contact-form.css",
		1.1,
		"all"
	  );	
	}
	if ($woocommerce_enable_print_pdf) {
	wp_enqueue_style(
		"print",
		plugin_dir_url(__FILE__) . "public/css/print.css",
		1.1,
		"all"
	  );
	}	
	wp_enqueue_script(
	  "configurator",
	  "https://configurator.ione360.com/js/threedconfigurator-standalone.bundle.min.js",
	  [],
	  true
	);


	 do_action("woocommerce_before_single_product"); 
	 
	 if ( post_password_required() ) {
		echo get_the_password_form(); // WPCS: XSS ok.
		return;
	}
	
 ?>
<div id="product-<?php the_ID(); ?>" <?php wc_product_class( '', $product ); ?>>
	<?php if ($configurator_Only !== 'yes'): ?>
		<?php do_action( 'woocommerce_before_single_product_summary' ); ?>		
		<div class="summary entry-summary">
			<?php do_action( 'woocommerce_single_product_summary' ); ?>
		</div>
	<?php endif; ?>
	<div class="selections-expand-wrapper test<?php echo $layout ?>" id="selections-expand" style="min-height:600px;">
		<div class="product-main-information" style="display:none;">
			<div class="product-essential-wrapper">
				<div class="product-essential">
					<div class="configurator-image active threed" id="threedconfigurator">
						<threed-configurator <?php if($configurator_useioneimages): ?>style="display:none;"<?php endif;?>></threed-configurator>
						<?php if($configurator_useioneimages): ?>
							<div class="product-placeholder" <?php if($configurator_useioneimages): ?>style="left:0;"<?php endif;?>>
								<div id="loading-gif" style="text-align: center; width:100%;">
									<img style="max-width:100px;" src="<?php echo esc_url(plugins_url("public/images/loading.gif", __FILE__)); ?>"/>
								</div>					
								<div class="image-wrapper" <?php if($configurator_useioneimages): ?>style="display:flex;justify-content:center;"<?php endif;?>>
									<img id="render_img" src="" />
								</div>
							</div>							
						<?php else: ?>
							<div class="animated-wrapper">
								<button id="SwitchView">	
									<span id="two_old">
										<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
											<path d="M25,11c7.72,0,14,6.28,14,14s-6.28,14-14,14-14-6.28-14-14,6.28-14,14-14m0-1c-8.29,0-15,6.72-15,15s6.71,15,15,15,15-6.71,15-15-6.72-15-15-15h0Z" fill="#484f60"/><g><path d="M23.34,30.72h-7.34v-1.85c.56-.49,1.12-1,1.68-1.55,.56-.55,1.01-1.02,1.35-1.42,.51-.59,.87-1.1,1.08-1.54,.21-.44,.32-.87,.32-1.3,0-.51-.14-.91-.41-1.19-.27-.28-.67-.42-1.18-.42-.38,0-.79,.1-1.21,.29-.43,.19-.82,.43-1.18,.73h-.2v-2.49c.3-.16,.74-.31,1.31-.47,.58-.16,1.16-.23,1.74-.23,1.17,0,2.06,.3,2.68,.88,.62,.59,.92,1.43,.92,2.5,0,.71-.15,1.38-.44,2.02-.3,.64-.75,1.3-1.35,1.97-.38,.42-.76,.81-1.15,1.16-.38,.35-.66,.6-.82,.74h4.2v2.15Z" fill="#484f60"/><path d="M33.44,22.29c-.37-.8-.88-1.44-1.52-1.91-.38-.28-.84-.5-1.39-.65-.55-.15-1.21-.23-1.97-.23h-3.39v11.21h3.29c.74,0,1.39-.07,1.93-.2,.54-.13,1.04-.36,1.5-.69,.61-.44,1.11-1.08,1.51-1.9,.4-.83,.6-1.76,.6-2.81s-.19-2.03-.56-2.83Zm-2.24,4.68c-.21,.5-.53,.91-.97,1.21-.26,.17-.52,.28-.78,.34-.27,.06-.69,.09-1.26,.09h-.61v-7.02h.61c.52,0,.91,.03,1.16,.08,.26,.05,.51,.15,.76,.3,.49,.3,.84,.71,1.06,1.23,.22,.52,.34,1.16,.34,1.89s-.1,1.37-.31,1.87Z" fill="#484f60"/></g></g></g></g><g id="c"/>
										</svg>
									</span>
									<span id="three_old">
										<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
											<path d="M25,11A14,14,0,1,1,11,25,14,14,0,0,1,25,11m0-1A15,15,0,1,0,40,25,15,15,0,0,0,25,10Z" fill="#484f60"/><path d="M19.65,28.46A2.94,2.94,0,0,1,17.87,28a2.46,2.46,0,0,0-1.5-.09,3.7,3.7,0,0,0,1.52.66,7.71,7.71,0,0,0,1.76-.09" fill="#484f60" opacity="0.5"/><path d="M18.56,21.81a2.83,2.83,0,0,0-1.94.66l1.19.08c.18,0,.72-.41.93-.49a2.38,2.38,0,0,1,1-.14l-1.17-.11" fill="#484f60" opacity="0.5"/><path d="M23,27.27a2.46,2.46,0,0,0-1.86-2.4c.54-.42,1.06-.66,1.36-1.33a3.16,3.16,0,0,0,.21-1.14c-.08-1.94-1.59-2.24-3.17-2.49a2.4,2.4,0,0,1,2.06,2.22,2.81,2.81,0,0,1-.5,1.88,5.74,5.74,0,0,1-1.09.85,2.58,2.58,0,0,1,1.9,2.61,3,3,0,0,1-2.52,3c1.25-.21,2.62-.39,3.27-1.62A3,3,0,0,0,23,27.27" fill="#484f60" opacity="0.5"/><path d="M27.06,21.33l.23,0,.29,0,.34,0h.45l.22,0,.21,0-.94-.15-.22,0H27l-.36,0-.29,0-.24,0-.17.05v7.6h1.72l.93-.14h0l-.21,0-.19,0h-.91l-.2,0-.17,0V21.37Z" fill="#484f60" opacity="0.5"/><path d="M34,24.6a5.42,5.42,0,0,0-1.78-4.26,6.62,6.62,0,0,0-2.68-1.11c2.63.67,3.74,3.18,3.68,5.72-.07,2.7-1.36,5.13-4.12,5.8,1.56-.38,3-.85,3.92-2.27a7.2,7.2,0,0,0,1-3.88" fill="#484f60" opacity="0.5"/><path d="M31.23,20a4.27,4.27,0,0,1,.81.78,4.5,4.5,0,0,1,.63,1,5.5,5.5,0,0,1,.41,1.3,8.27,8.27,0,0,1,.14,1.55,8.71,8.71,0,0,1-.15,1.67,6,6,0,0,1-.41,1.38A4.92,4.92,0,0,1,32,28.86a4.43,4.43,0,0,1-.76.84,4.91,4.91,0,0,1-1,.65,6.62,6.62,0,0,1-1.21.41,8.4,8.4,0,0,1-1.36.2,10.34,10.34,0,0,1-1.47,0l-.84-.07-.7-.09-.58-.09-.45-.09V19.51l.65-.15.74-.13.81-.1.86-.08a13.33,13.33,0,0,1,1.4,0,8.59,8.59,0,0,1,1.2.14,5.4,5.4,0,0,1,1,.33A4.45,4.45,0,0,1,31.23,20Zm-4.48,8.89a4.15,4.15,0,0,0,1.48-.19A2.85,2.85,0,0,0,29.39,28a3.27,3.27,0,0,0,.76-1.3,5.94,5.94,0,0,0,.27-1.89,5.14,5.14,0,0,0-.25-1.71,3,3,0,0,0-.7-1.18,2.77,2.77,0,0,0-1.1-.67A4,4,0,0,0,27,21.08l-.36,0-.29,0-.24,0-.17.05v7.6l.17,0,.2,0,.22,0h.26" fill="#484f60"/><path d="M18.74,19.88a3.43,3.43,0,0,1,1.19.13,2.33,2.33,0,0,1,.9.51,2.3,2.3,0,0,1,.57.81,2.85,2.85,0,0,1,.19,1,3,3,0,0,1-.1.81,2.45,2.45,0,0,1-.8,1.26,3,3,0,0,1-.7.41v0a2.45,2.45,0,0,1,.73.3,2.48,2.48,0,0,1,.61.56,2.63,2.63,0,0,1,.41.78,3,3,0,0,1,.15,1,3.19,3.19,0,0,1-.25,1.29,2.68,2.68,0,0,1-.72,1,3,3,0,0,1-1.11.6,3.93,3.93,0,0,1-1.44.14,5.63,5.63,0,0,1-.75-.11,5.16,5.16,0,0,1-.66-.2,4.72,4.72,0,0,1-.55-.26,2.25,2.25,0,0,1-.41-.28l.37-1.74.32.21.44.21a3.65,3.65,0,0,0,.53.19,3.56,3.56,0,0,0,.57.09,1.93,1.93,0,0,0,.66-.08,1.12,1.12,0,0,0,.48-.27,1.19,1.19,0,0,0,.3-.43,1.51,1.51,0,0,0,.1-.53,1.58,1.58,0,0,0-.15-.68,1.26,1.26,0,0,0-.38-.47,1.73,1.73,0,0,0-.54-.28,2,2,0,0,0-.61-.09h-.77V24.06h.74a1.77,1.77,0,0,0,.5-.07,1.42,1.42,0,0,0,.47-.21,1.06,1.06,0,0,0,.36-.37,1.11,1.11,0,0,0,.14-.56,1.18,1.18,0,0,0-.08-.43.79.79,0,0,0-.23-.34,1.07,1.07,0,0,0-.38-.21,1.55,1.55,0,0,0-.54-.06,2.74,2.74,0,0,0-.5.08,4.24,4.24,0,0,0-.47.17l-.41.21-.3.21-.37-1.67a3.2,3.2,0,0,1,.43-.31,5.26,5.26,0,0,1,.58-.27A4.78,4.78,0,0,1,18,20,4.88,4.88,0,0,1,18.74,19.88Z" fill="#484f60"/>
										</svg>
									</span>
								</button>						
							</div>
							<div class="product-placeholder">
								<div id="loading-gif" style="text-align: center; width:100%;">
									<img style="max-width:100px;" src="<?php echo esc_url(plugins_url("public/images/loading.gif", __FILE__)); ?>"/>
								</div>					
								<div class="image-wrapper">
									<img id="render_img" src="" />
								</div>
							</div>
							<?php if($configurator_renderButton): ?>
								<div class="force-render">
									<button id="RenderIcon" onclick="getRenderImage()" class="getrender" title="Get render">
										<span>
											<svg id="Icons" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
												<defs><style>.cls-1{fill:none;stroke:#484f5f;stroke-miterlimit:10;}.cls-2{fill:#484f5f;}.cls-3{fill:#fff;}</style></defs>
												<g id="Icons-2" data-name="Icons"><rect class="cls-1" x="16" y="21.97" width="26" height="19.07"/>
												<polygon class="cls-2" points="42 38.49 33.33 31.5 29 35.01 23.8 28.9 16 37.65 16 41.03 42 41.03 42 38.49"/>
												<circle class="cls-2" cx="37.23" cy="26.73" r="2.17"/><circle class="cls-3" cx="18" cy="18.97" r="10"/>
												<path class="cls-2" d="M18,9.63A9.34,9.34,0,1,1,8.67,19,9.34,9.34,0,0,1,18,9.63M18,9A10,10,0,1,0,28,19,10,10,0,0,0,18,9Z"/>
												<path class="cls-2" d="M22.22,17.18a5.19,5.19,0,0,0-.42-.77,4.6,4.6,0,0,0-.56-.68,4.5,4.5,0,0,0-.68-.56,4.21,4.21,0,0,0-.78-.42,4.1,4.1,0,0,0-.86-.27,4.75,4.75,0,0,0-1.84,0,4.1,4.1,0,0,0-.86.27,4.21,4.21,0,0,0-.78.42,4.5,4.5,0,0,0-.68.56l-.27.29L14,15.6a3.26,3.26,0,0,1,.31-.33A5.31,5.31,0,0,1,16,14.14a5.65,5.65,0,0,1,1-.3,5.3,5.3,0,0,1,2.1,0,5.65,5.65,0,0,1,1,.3,5.31,5.31,0,0,1,1.66,1.13,4.76,4.76,0,0,1,.64.77,5.1,5.1,0,0,1,.48.89Z"/><polygon class="cls-2" points="12 14.23 16.94 16.79 13.19 17.98 12 14.23"/><path class="cls-2" d="M18,24.2A5.27,5.27,0,0,1,17,24.09a5.65,5.65,0,0,1-1-.3,5.86,5.86,0,0,1-.89-.48,6.7,6.7,0,0,1-.77-.64,5.31,5.31,0,0,1-.64-.78,5.1,5.1,0,0,1-.48-.89l.6-.25a5.86,5.86,0,0,0,.42.78,4.77,4.77,0,0,0,2,1.66,4.77,4.77,0,0,0,.86.26,4.39,4.39,0,0,0,1.84,0,4.77,4.77,0,0,0,.86-.26,4.55,4.55,0,0,0,.78-.43,4.5,4.5,0,0,0,.68-.56l.27-.29.5.42c-.1.12-.2.23-.31.34a6.7,6.7,0,0,1-.77.64,5.86,5.86,0,0,1-.89.48,5.65,5.65,0,0,1-1,.3A5.27,5.27,0,0,1,18,24.2Z"/><polygon class="cls-2" points="24 23.7 19.06 21.15 22.81 19.95 24 23.7"/></g>
											</svg>
										</span>
									</button>
								</div>
							<?php endif; ?>
						<?php endif; ?>
						<div class="force-expand fixedElement" id="scroller-anchor">
							<button id="ExpandIcon" class="getexpand" onclick="getExpandView()" title="Get expand">
								<span id="ExpandText">									
									<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
										<path d="M38,38.17H12v-26H38ZM13.24,36.93H36.76V13.4H13.24Z" fill="#484f60"/><polygon points="17.35 32.81 17.35 26.75 19.46 28.86 28.69 19.63 26.59 17.52 32.65 17.52 32.65 23.58 30.54 21.47 21.31 30.71 23.41 32.81 17.35 32.81" fill="#484f60"/>
									</svg>
								</span>
							</button>
							<span id="ScrollGesture">scroll</span>	
						</div>					
					</div>
					<div class="product-info">
						<?php if($configurator_showName): ?>
							<div class="configurator-data">
								<div class="product-name">
									<h2 id="title_wrapper"><?php echo $product->get_title(); ?></h2>
								</div>
								<div class="short-description">
									<?php
									$product_id = $product->get_id(); // Get the product ID
									$product_post = get_post($product_id); // Get the product post object

									if ($product_post) {
										$product_excerpt = $product_post->post_excerpt;
										echo '<p>' . esc_html($product_excerpt) . '</p>';
									}
									?>
								</div>
							</div>
						<?php endif; ?>
						<div class="selections" id="selections">
							<div class="mobile mobile-selections-header" id="mobheader" onclick="getMobileSelections()"><span>Configure</span></div>
							<threed-selections id=selector></threed-selections>
						</div>
						<div class="cta-buttons">
							<?php if ($configurator_addToCart !== 'yes' && $configurator_Only === 'yes'): ?>
								<div class="addtocart">
										<button	id="add-to-cart-modal" > Add to Cart </button>
									<div style="display: none;">
										<?php do_action("woocommerce_simple_add_to_cart", 30); ?>
										<?php do_action("add_configurator_field", 30); ?>
									 </div>
								</div>
							<?php endif; ?>					
							<?php if($woocommerce_enable_print_pdf): ?>
								<div class="addtoprint" id="pdf_click">
									<button class="addto primary to-pdf">
										<?php if($configurator_printText !== ''): ?>
											<span><?php echo $configurator_printText ?></span>
										<?php else: ?>
											<span>Print to pdf</span>
										<?php endif; ?>
									</button>
								</div>
								<span class="print-config" id="print_config" style="display:none"></span>							
							<?php endif; ?>
							<?php if($woocommerce_enable_contact_form): ?>
								<div class="quote-btn" id="quote_btn">
									<button class="addto primary to-mail">
										<?php if($configurator_contactText !== ''): ?>	
											<span><?php echo $configurator_contactText ?></span>
										<?php else: ?>
											<span>Contact us</span>
										<?php endif; ?>
									</button>
								</div>							
							<?php endif; ?>
						</div>
					</div>
					<?php if($woocommerce_enable_contact_form): ?>
						<?php include(plugin_dir_path(__FILE__) . 'templates/contact-form.php'); ?>
					<?php endif; ?>					
				</div>
			</div>
		</div>
	</div>
<?php do_action("woocommerce_after_single_product_summary"); ?>
</div>

 <style>
	<?php if ($configurator_buttonsScene): ?>
		.configurator-image button, div.mobile.mobile-selections-header:after {background-color:<?php echo $configurator_buttonsScene ?> !important}
	<?php endif; ?>
	<?php if ($configurator_buttonsTextScene): ?>
		.configurator-image div:not(.powered-by-wrapper) button, button#standalone_show_measurements:after {color:<?php echo $configurator_buttonsTextScene ?> !important}
		.configurator-image div:not(.powered-by-wrapper) svg path, .configurator-image div:not(.powered-by-wrapper) svg polygon, .configurator-image div:not(.powered-by-wrapper) svg circle {fill:<?php echo $configurator_buttonsTextScene ?> !important} 	
	<?php endif; ?>
	<?php if ($configurator_buttonsCta): ?>
		.product-info .cta-buttons button, .product-info .fta-buttons button {background-color:<?php echo $configurator_buttonsCta ?> !important}
	<?php endif; ?>
	<?php if ($configurator_buttonsTextCta): ?>
		.product-info .cta-buttons button span {color:<?php echo $configurator_buttonsTextCta ?> !important}
	<?php endif; ?>	
	<?php if ($configurator_hideTotalPrice): ?>
		.selections .sum {display:none !important;}
		.product-info .cta-buttons {margin-top: 30px;display:block;width:100%;float:left}
	<?php endif; ?>
	<?php if ($configurator_headingColor): ?>
		.configurator-data h4, .mobile-selections-header span, .selections .answer-slideout .title h3, .answer-slideout .selections .title span {color:<?php echo $configurator_headingColor ?> !important}
	<?php endif; ?>	
	<?php if ($configurator_textColor): ?>
		.selections .titles span, .selections .sum .price, .selections .answer-slideout .cards .description-wrapper span {color:<?php echo $configurator_textColor ?> !important}
	<?php endif; ?>	
	<?php if ($configurator_labelsColor): ?>
		.selections label {color:<?php echo $configurator_labelsColor ?> !important}
	<?php endif; ?>
	<?php if ($configurator_btnRadius): ?>
		.configurator-image button, .configurator-image button img {border-radius: <?php echo $configurator_btnRadius?>% !important;} 
	<?php endif; ?>
	<?php if ($woocommerce_scenewidth_canvas): ?>
		<?php $configurator_selectionsWidth = 100 - $woocommerce_scenewidth_canvas; ?>
		@media (min-width: 992px) {
			.product-essential .configurator-image {width:<?php echo $woocommerce_scenewidth_canvas ?>% !important}
			.product-essential .product-info {width: <?php echo $configurator_selectionsWidth ?>% !important}
			body.expanded .product-essential .configurator-image {width: 100% !important;}			
			.configurator-image threed-configurator {max-width:100% !important}
		}
	<?php endif; ?>
	<?php if($woocommerce_enable_print_pdf && $configurator_addToCart !== 'yes' && $configurator_Only === 'yes'): ?>
		.cta-buttons {gap: 5px !important;}
	<?php endif; ?>
</style>
 <script>
	 connectorSettings = {
 		url: '<?php echo esc_url($configurator_url); ?>', // iOne url
		ajaxUrl: '<?php echo esc_url($configurator_url); ?>',
 		schema: '<?php echo esc_attr($configurator_schema); ?>', // iOne scheme
 		version: '<?php echo esc_attr($configurator_version); ?>', // iOne version
 		assetPath: 'https://cdn.ione360.com/content43/', // image cdn 3d models
 		assetIndex: '<?php echo esc_textarea($configurator_assets); ?>',
		threeDAssetPath: '<?php echo esc_textarea($configurator_cdn); ?>',
		cameraConfig: '<?php echo esc_textarea($configurator_camera); ?>',
		sceneBackground: '<?php echo esc_textarea($configurator_background); ?>',
 		languageCode: '<?php echo esc_textarea($configurator_language); ?>', // German -> DE, English -> EN
 		gtm: '<?php echo esc_textarea($configurator_gtm); ?>', // GTM code
		options: {
				showStandaloneARButton: <?php if (empty($configurator_AREnabled)) {echo "false";} else {echo "true";} ?>,
				arEnabled: <?php if (empty($configurator_AREnabled)) {echo "false"; } else {echo "true";} ?>,
				useStandaloneFloors: <?php if (empty($configurator_standaloneFloors)) {echo "false"; } else {echo "true"; } ?>,
				inlineAnswers: <?php if (empty($configurator_inlineAnswer)) {echo "false"; } else {echo "true"; } ?>,
				showAsConfigured: <?php if (empty($configurator_showAsConfigured)) {echo "false"; } else {echo "true"; } ?>,
				/*vrEnabled: <?php if (empty($configurator_vrEnabled)) {echo "false"; } else {echo "true"; } ?>,*/
				show3DWatermark: <?php if (empty($configurator_show3dwatermark)) {echo "false";} else {echo "true"; } ?>,
				showTagFilter: <?php if (empty($configurator_showtagfilter)) {echo "false"; } else {echo "true"; } ?>,
				showZoomButton: <?php if (empty($configurator_showzoombutton)) {echo "false"; } else {echo "true"; } ?>,
				showMeasurementsButton: <?php if (empty($configurator_showdimensions)) {echo "false"; } else {echo "true"; } ?>,
				showDownloadButton: <?php if (empty($configurator_showdownload)) {echo "false";} else {echo "true";} ?>,				  
				useNewRender: true
			},
		<?php if($configurator_userenders): ?>
			newRenderParameters: {
					host: "<?php echo esc_textarea($configurator_renderhost); ?>",
					port: <?php echo esc_textarea($configurator_renderport); ?>,
					hdriIntensity:<?php echo esc_attr($configurator_enviromentIntensity); ?>,
					imageWidth: <?php echo esc_attr($configurator_render_imageWidth); ?>,
					imageHeight: <?php echo esc_attr($configurator_render_imageHeight); ?>,
					iterations: <?php echo esc_attr($configurator_render_iterations); ?>
				
				}
		<?php endif; ?>
	}

		document.addEventListener('DOMContentLoaded', function(){

			// Adds the render button to the 2D image in the configurator
			<?php $configurator_renderbutton = get_option("configurator_render_button"); ?>
			var forcerenderbtn = '<?php if (empty($configurator_renderbutton)) {
				echo "false";
			} ?>';
			//if ( forcerenderbtn === 'false'){
			//	document.getElementById("forcerender").style.display = "none";
			//};

			/* Retrieving sku parameter from Woocommerce */
			<?php $configurator_sku = esc_attr($product->get_meta("_configurator_sku")); ?>
			<?php $configurator_convertedsku = esc_attr($product->get_sku()); ?>

			/*	 Woocommerce sku that was configured in the backend of the product page 	*/
				let sku =  '<?php if (empty($configurator_sku)) {
					echo esc_textarea($configurator_convertedsku);
				  } else {
					echo esc_textarea($configurator_sku);
				  } ?>';
						
			/* Setting sku and settings on selector object */
			document.getElementById('selector').setAttribute('sku', sku);
			document.getElementById('selector').setAttribute('settings', JSON.stringify(connectorSettings));

	
		// add to the configurated product the description of the product when adding to cart.
		document.getElementById('selector').addEventListener('onArticleCreated', function(article) {
			console.log(event.detail);
			const cartData = article.detail;
			let totalSalesPrice = 0;
			let foundConfigText = false;
			const obj = JSON.parse(cartData, function (key, value) {
				if (!foundConfigText && key === 'configurationText') {
					document.getElementById("configurator_text").value = value;
					foundConfigText = true;
				}
				if (key == 'salesPrice') {
					totalSalesPrice += parseFloat(value);	 				
				}
			});
			document.getElementById("configurator_price").value = totalSalesPrice;
		});
		<?php if($configurator_useioneimages): ?>
		document.getElementById('selector').addEventListener('onImageReceived', function (event) {
			document.getElementById('render_img').src = event.detail;
			document.getElementById("loading-gif").style.display = "none";
		});
					
		document.getElementById('selector').addEventListener('onArticleReceived', function (event) {
			console.log(event.detail);								
			if(event.detail.images['0']) {
				document.getElementById('render_img').src = ('data:image/png;base64,') + event.detail.images['0'].documentBody;
			}
			document.getElementById("loading-gif").style.display = "none";
		});	
		<?php endif; ?>
		// remove the loading .gif and clear the picture when the render image is recieved
		<?php if($configurator_userenders && !$configurator_useioneimages): ?>
			document.getElementById('selector').addEventListener('onRenderImageReceived', function (event) {
				random = Math.floor((Math.random()*100) + 1);
				image = event.detail + '?_' + random;
				//console.log(image);
				document.getElementById("render_img").src = event.detail;
				document.getElementById("configurator_image").value = event.detail;
				 document.getElementById("loading-gif").style.display = "none";
					 document.getElementById("render_img").style.opacity = "1";
			});

			document.getElementById('selector').addEventListener('onReadyToRender', function (event) {
				if (event.detail) {
					document.getElementById("loading-gif").style.display = "block";
					document.getElementById('selector').renderImage();
				}
			});	
			<?php elseif ($configurator_useioneimages): ?>
				document.getElementById("loading-gif").style.display = "none";
			<?php else: ?>
				document.getElementById("loading-gif").style.display = "none";
				document.getElementById("SwitchView").style.display = "none";
			<?php endif; ?>					
			document.getElementById('selector').addEventListener('onAnswersAvailable', function (event) {
				if (event.detail == false) {
					jQuery(".addtocart").show();
				} else {
					jQuery(".addtocart").hide();
				}
			})
			document.getElementById('selector').addEventListener('onSelectionsReceived', function (event) {
				//console.log(event.detail)
				<?php if($configurator_userenders): ?>
					document.getElementById("loading-gif").style.display = "block";
					document.getElementById("render_img").style.opacity = "0.5";
				<?php elseif ($configurator_useioneimages): ?>	
					document.getElementById("loading-gif").style.display = "none";
					document.getElementById("render_img").style.opacity = "1";
				<?php endif; ?>
				
			})
			/* Mobile selection drop (bottom) */
			jQuery("#selections-click").click(function(){
				jQuery("#selections-expand").toggleClass("expand-mobile");
			});
			jQuery("#title_drop").click(function(){
				jQuery("#title_desc").toggleClass("expand-desc");
				jQuery("#title_drop").toggleClass("expand-desc");
			});	
			<?php if(!$configurator_useioneimages): ?>
				if(jQuery(window).width() < 786) {
					var $anchor = jQuery(".fixedElement");
					var $scroller = jQuery('#ExpandIcon');
					var $bottom = jQuery(".product-info");
					var $gesture = jQuery(".force-expand:after");
					var move = function() {
						var st = jQuery(window).scrollTop();
						var ot = $anchor.offset().top;
						var bt = $bottom.offset().top;
						if(st > ot && st < (bt - 70)) {
							$scroller.css({
								position: "fixed",
								top: "0px",
								right: "15px"
							});
							$anchor.addClass('gesture');
						} else if (st > (bt - 70)){
							$scroller.css({
								position: "absolute",
								bottom: "0px",
								top: "initial",
								right: "0px"
							});
						} else {
							$scroller.css({
								position: "absolute",
								bottom: "initial",
								top: "0px",
								right: "0px"
							});	
							$anchor.removeClass('gesture');
						}
					};
					jQuery(window).scroll(move);
					move();
				}
			<?php endif; ?>
			setTimeout(function() {
				jQuery('#loading-gif').fadeOut();
				jQuery('.product-main-information').fadeIn();
			},2000);
			jQuery("#SwitchView").click(function() {
				jQuery('.configurator-image').toggleClass('twod');
				jQuery('.configurator-image').toggleClass('threed');
			});
			// When pressing add to cart, this will press the hidden add to cart button from Woocommerce
			jQuery("#add-to-cart-modal").on('click', function(e){
				e.preventDefault();
				let selector = document.getElementById('selector');
				 selector.addToCart();
				 let listener = function() {
				jQuery('.single_add_to_cart_button').trigger('click');

					selector.removeEventListener('onArticleCreated', listener);
				 }
				 selector.addEventListener('onArticleCreated', listener);
				 });
			<?php if($woocommerce_enable_print_pdf): ?>				
				jQuery("#pdf_click").click(function() {
					window.addEventListener('afterprint', function() {
						jQuery(wrapperDiv).remove();
					});											
					var dataURL = document.getElementById('selector').getCanvasImage();
					var prodInfo = document.getElementById('print_config');
					<?php if($configurator_showName): ?>
						var prodName = document.getElementById('title_wrapper');
					<?php endif; ?>
					var prodCopy = jQuery(prodInfo).clone();
					var selectInfo = jQuery('.summary-line');
					var selectCopy = jQuery(selectInfo).clone();
					var wrapperDiv = document.createElement('div');
					var innerDiv = document.createElement('div');
					var headerDiv = document.createElement('div');
					var topDiv = document.createElement('div');
					var bottomDiv = document.createElement('div');
					var bot_leftDiv = document.createElement('div');
					var bot_rightDiv = document.createElement('div');
					var imageDiv = document.createElement('img');
					jQuery(wrapperDiv).append(innerDiv);
					jQuery(innerDiv).append(headerDiv);
					jQuery(innerDiv).append(topDiv);	
					jQuery(innerDiv).append(bottomDiv);
					jQuery(topDiv).append(imageDiv);					
					jQuery(bottomDiv).append(bot_leftDiv);
					jQuery(bottomDiv).append(bot_rightDiv);					
					jQuery(wrapperDiv).addClass('pdf-container');
					jQuery(innerDiv).addClass('pdf-inner');
					jQuery(headerDiv).addClass('pdf-header');
					jQuery(topDiv).addClass('pdf-top');
					jQuery(bottomDiv).addClass('pdf-bottom');
					jQuery(bot_leftDiv).addClass('pdf-left');
					jQuery(bot_rightDiv).addClass('pdf-right');					
					<?php if($configurator_showName): ?>
						var prodName = document.getElementById('title_wrapper');
						var nameCopy = jQuery(prodName).clone();
						jQuery(headerDiv).append(nameCopy);
					<?php endif; ?>					
					jQuery('body').append(wrapperDiv);
					
					jQuery(imageDiv).attr('src', dataURL);
					jQuery(bot_leftDiv).html(prodCopy);
					jQuery(bot_rightDiv).html(selectCopy);
					setTimeout(function() {
						window.print();		
					},200);					
				});					  			
			<?php endif; ?>	
		}, false);
		function getRenderImage() {
			document.getElementById("loading-gif").style.display = "block";
			document.getElementById('selector').forceRenderImage();
		}
		
		function getExpandView() {
			 document.body.classList.toggle("expanded");
		}
		function getMobileSelections() {
			 document.getElementById("selections").classList.toggle("expanded");
		}		

	</script>
	
<?php do_action('woocommerce_after_single_product'); ?>
<?php get_footer("shop");

/* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */
