@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb.Frontend.Navigation
@using Dynamicweb.Ecommerce.ProductCatalog
@using Dynamicweb.Environment

@{
	ProductListViewModel productList = null;
	if (Dynamicweb.Context.Current.Items.Contains("ProductList"))
	{
		productList = (ProductListViewModel)Dynamicweb.Context.Current.Items["ProductList"];
	}
}

@if (productList is object)
{
	string searchParameter = Dynamicweb.Context.Current.Request.GetString("q");

	string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-4");

	string groupName = productList?.Group?.Name != null ? productList.Group.Name : "";
	string headerName = searchParameter != "" ? Translate("Search results for") + ": " + searchParameter : groupName;

	bool hideTitle = Model.Item.GetBoolean("HideTitle");

	@* if we're on a search result page, set the search term as the Meta Title *@
	if (!string.IsNullOrEmpty(searchParameter))
	{
		Dynamicweb.Frontend.PageView.Current().Meta.Title = Translate("Search results for") + ": " + searchParameter;
	}

	string layout = Model.Item.GetRawValueString("Layout", "text-start");

	<div class="item_@Model.Item.SystemName.ToLower()" data-dw-colorscheme="@Model.ColorScheme?.Id">
		@if (!string.IsNullOrEmpty(headerName))
		{
			<div class="grid gap-0">
				@if (layout == "text-start")
				{
					if (!hideTitle) { 
						<div class="g-col-12 g-col-lg-9">
							<h1 class="@titleFontSize m-0">@headerName</h1>
						</div>
						<div class="g-col-12 g-col-lg-3 text-lg-end mb-3 mb-lg-0">
							@productList.TotalProductsCount @Translate("products")
						</div>
					}
					else
					{
						<div class="g-col-12">
							<div class="@titleFontSize m-0">@productList.TotalProductsCount @Translate("products")</div>
						</div>
					}
				}
				else
				{
					if (!hideTitle)
					{
						<div class="g-col-12 text-center d-flex flex-column align-items-center">
							<h1 class="@titleFontSize m-0">@headerName</h1>
						</div>
						<div class="g-col-12 text-center mb-3">
							@productList.TotalProductsCount @Translate("products")
						</div>
					}
					else
					{ 
						<div class="g-col-12">
							<div class="@titleFontSize m-0">@productList.TotalProductsCount @Translate("products")</div>
						</div>
					}
				}
			</div>
		}
		else if (Pageview.IsVisualEditorMode)
		{
			<div class="alert alert-dark m-0" role="alert">
				<span>@Translate("Product list header: The header will be shown here, if any")</span>
			</div>
		}
	</div>
}
else if (Pageview.IsVisualEditorMode)
{
	<div class="alert alert-dark m-0" role="alert">
		<span>@Translate("Product list header: The header will be shown here, if any")</span>
	</div>
}
