<?php if (false !== $data = $block->getDetailPushForward()): ?> <script data-ommit="true" nonce="<?php echo $block->generateNonce() ?>">
		<?php
		/**
		 * AdWords Dynamic Remarketing
		 */
		?> <?php if (true): ?>

				(params => {
					window.google_tag_params.ecomm_pagetype = params.ecomm_pagetype;
					window.google_tag_params.ecomm_category = params.ecomm_category;

					window.google_tag_params.ecomm_prodid = (pid => {
						if (window.location.hash) {
							let hash = window.location.hash.substring(1);

							Object.entries(AEC.CONFIGURABLE_SIMPLES).forEach(([key, configurable]) => {
								Object.entries(configurable.configurations).forEach(([key, value]) => {
									let compare = [value.value, value.label].join('=');

									if (-1 !== hash.indexOf(compare)) {
										pid = configurable.id;
									}
								});
							});
						}

						return pid;

					})(params.ecomm_prodid);

					window.google_tag_params.ecomm_totalvalue = params.ecomm_totalvalue;

				})(<?php echo json_encode($data->google_tag_params) ?>);

			window.google_tag_params.returnCustomer = <?php echo $block->getHelper()->getIsReturnCustomer() ?>;

		<?php endif ?> <?php if ($block->getHelper()->supportDynx()): ?>

			window.google_tag_params.dynx_pagetype = 'offerdetail';
			window.google_tag_params.dynx_itemid = window.google_tag_params.ecomm_prodid;
			window.google_tag_params.dynx_totalvalue = window.google_tag_params.ecomm_totalvalue;

		<?php endif ?> <?php
		/**
		 * Detail push
		 */
		?> (payload => {
				AEC.CookieConsent.queue(() => {
					AEC.Cookie.detail(payload).push(dataLayer);

				}).process();

				<?php
				/**
				 * Private browser fallback
				 */
				?> dataLayerTransport.push(payload);

				<?php if ($block->getHelper()->supportFacebookConversionsApi()): ?>

						(async data => {
							if (AEC?.Const?.META_CONVERSIONS_API_EVENTS?.includes('ViewContent')) {
								AEC.Request.post(AEC.url('datalayer/index/facebook'), {
									payload: data,
									form_key: <?php echo json_encode($block->getHelper()->getFormKey()) ?>
								}, response => {
									return true;
								});
							}

						})(payload);

				<?php endif ?> document.addEventListener("DOMContentLoaded", () => {
					let items = (function() {
						var items = [],
							trace = {};

						document.querySelectorAll('[data-event=<?php echo \Anowave\Ec\Helper\Constants::EVENT_PRODUCT_CLICK ?>]').forEach(element => {
							let entity = {

								item_id: element.dataset.id,
								item_id_numeric: parseInt(element.dataset?.numeric),
								item_name: element.dataset.name,
								item_list_name: element.dataset.list,
								item_list_id: element.dataset.list,
								item_brand: element.dataset.brand,
								category: element.dataset.category,
								price: parseFloat(element.dataset.price),
								index: parseFloat(element.dataset.position),
								currency: AEC.GA4.currency,
								quantity: 1,
								remarketingFacebookId: element.dataset.remarketingFacebookId,
								remarketingAdwordsId: element.dataset.remarketingAdwordsId,
								google_business_vertical: 'retail',
								<?php echo $block->getHelper()->getStockDimensionIndex(true) ?>: element.dataset['<?php echo $block->getHelper()->getStockDimensionIndex(true) ?>']
							};

							Object.assign(entity, entity, AEC.GA4.augmentCategories(entity));

							var attributes = element.dataset.attributes;

							if (attributes) {
								Object.entries(JSON.parse(attributes)).forEach(([key, value]) => {
									entity[key] = value;
								});
							}

							if (!trace.hasOwnProperty(entity.item_id)) {
								trace[entity.item_id] = true;

								items.push(entity);
							}
						});

						return items;
					})();

					if (items.length) {
						let data = <?php echo json_encode(
										[
											'currency' => $block->getHelper()->getCurrency(),
											'ecommerce' =>
											[
												'item_list_id'     => __('Mixed Products'),
												'item_list_name'   => __('Mixed Products')
											],
											'event' => \Anowave\Ec\ViewModel\ProductList::EVENT
										]
									) ?>;

						data.ecommerce['items'] = items;

						AEC.CookieConsent.queue(() => {
							AEC.Cookie.impressions(data).push(dataLayer);

						}).process();
					}
				});

			})(<?php echo $data->payload ?>);


		<?php
		/**
		 * Grouped product map
		 */
		?> window.G = <?php echo $data->group ?>;

		<?php if ($block->getHelper()->useGroupAssociatedViewEvent()): ?>

			if (window.G) {
				window.G.forEach(entity => {
					AEC.CookieConsent.queue(() => {
						let g = <?php echo json_encode(
									[
										'currency' => $block->getHelper()->getCurrency(),
										'ecommerce' =>
										[
											'item_list_id'     => __('Grouped products'),
											'item_list_name'   => __('Grouped products')
										],
										'event' => \Anowave\Ec\Helper\Constants::EVENT_VIEW_ITEM,
										'value' => 0
									]
								)
								?>;

						g.value = entity.price;

						g.ecommerce['items'] = [entity];

						AEC.Cookie.detail(g).push(dataLayer);

					}).process();
				});
			}

		<?php endif ?> <?php if ($block->getHelper()->facebook()): ?>

				(() => {
					let track = () => {

						const payload = <?php echo $data->fbq ?>;

						fbq('track', 'ViewContent', payload, {
							eventID: AEC.UUID.generate({
								event: 'ViewContent'
							})
						});

						document.dispatchEvent(new CustomEvent('meta.track', { detail: { event: 'ViewContent', payload: payload }}));
					};

					if (AEC.Const.COOKIE_DIRECTIVE) 
					{
						AEC.CookieConsent.queue(() => {
							typeof fbq !== 'undefined' ? track() : AEC.EventDispatcher.on('ec.facebook.loaded', track);
						});
					} else {

						typeof fbq !== 'undefined' ? track() : AEC.EventDispatcher.on('ec.facebook.loaded', track);
					}

				})();

		<?php endif ?> <?php
		/**
		 * Hyva configurables
		 */
		?> (() => 
		{
			let permutations = 0;

			Object.entries(AEC.CONFIGURABLE_SIMPLES).forEach(([key, configurable]) => {
				
				permutations = Object.keys(configurable.configurations).length;
			});

			window.lastViewedSimpleId = null;

			window.addEventListener('configurable-selection-changed', event => 
			{	
				const key = event?.detail?.productIndex;

				const selectedAttributes = Object.values(event.detail.selectedValues || {});

				if (permutations > 0 && permutations !== selectedAttributes.length)
				{
					return;
				}

				if (key && AEC.CONFIGURABLE_SIMPLES.hasOwnProperty(key))
				{
					simple = AEC.CONFIGURABLE_SIMPLES[key];

					if (window.lastViewedSimpleId === simple.id) {
						return;
					}

					window.lastViewedSimpleId = simple.id;
				
					let list = 'Configurable variants', item = 
					{
						item_id: 			AEC.simples ? simple.id : simple.parent,
						item_name:  		AEC.simples ? simple.name : simple.parent_name,
						item_list_name: 	list,
						item_list_id: 		list,
						price: 				Number(simple.price),
						quantity:			1
					};
					
					if (simple.hasOwnProperty('configurations'))
					{
						item['configurations'] = simple.configurations;
					}
					
					if (simple.hasOwnProperty('configurations'))
					{
						let variant = [];

						simple.configurations.forEach(configuration => 
						{
							variant.push(configuration.variant);
						});

						if (!AEC.simples)
						{
							item['item_variant'] = variant.join(',');
						}
					}

					if (AEC.simples)
					{
						(button => { button?.dataset && (button.dataset.simpleId = simple?.id ?? '')})(document.querySelector('[id=product-addtocart-button]'));
					}
				
					dataLayer.push(
					{
						event:'view_item',
						ecommerce:
						{
							currency: AEC.currencyCode,
							value: item.price,
							items: [item]
						}
					});
				}
			});

		})();</script><?php endif ?>