@inherits ViewModelTemplate<ProductViewModel>
@using Dynamicweb.Rendering
@using Dynamicweb.Ecommerce.ProductCatalog

@{
	if (Dynamicweb.Context.Current?.Items.Contains("ProductDetails") ?? false)
	{
		Dynamicweb.Context.Current.Items["ProductDetails"] = Model;
	}
	else
	{
		Dynamicweb.Context.Current?.Items.Add("ProductDetails", Model);
	}
	var detailPage = GetPageIdByNavigationTag("ProductDetailPage");
}

<script>
	window.dataLayer = window.dataLayer || [];
	window.dataLayer.push({
		event: "view_item",
		ecommerce: {
			currency: "@Model.Price.CurrencyCode",
			value: @Model.Price.ToStringInvariant(),
			items: [
				{
					item_id: "@Model.Number",
					item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(Model.Name)",
					@if (!string.IsNullOrEmpty(Model.VariantName))
					{
						<text>item_variant: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(Model.VariantName)",</text>
					}
					currency: "@Model.Price.CurrencyCode",
					price: @Model.Price.ToStringInvariant(),
					discount: @Model.Discount.ToStringInvariant()
				}
			]
		}
	});
</script>

<article itemscope itemtype="https://schema.org/Product">
	@RenderGrid(Model.PrimaryOrDefaultGroup.PrimaryPageId > 0 ? Model.PrimaryOrDefaultGroup.PrimaryPageId : detailPage)
</article>
