@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");

	bool hideTitle = Model.Item.GetBoolean("HideGroupTitle");
	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 hideDescription = Model.Item.GetBoolean("HideGroupDescription");
	string groupDescription = productList?.Group?.Description != null ? productList.Group.Description : "";
	string descriptionFontSize = Model.Item.GetRawValueString("DescriptionFontSize", "fs-6");

	string maxWidth = Model.Item.GetRawValueString("TextReadability", "max-width-on");
	maxWidth = maxWidth == "max-width-on" ? " mw-75ch" : maxWidth;
	maxWidth = maxWidth == "max-width-off" ? "" : maxWidth;

	string layout = Model.Item.GetRawValueString("Layout", "text-start");
	string autoMargin = layout == "text-start" ? "my-auto" : "m-auto";

	if ((!string.IsNullOrEmpty(headerName) && !hideTitle) || !string.IsNullOrEmpty(groupDescription))
	{
		<div class="h-100 item_@Model.Item.SystemName.ToLower()" data-dw-colorscheme="@Model.ColorScheme?.Id">
			<div class="@(layout) @(maxWidth) w-100 @autoMargin">
				@if (!hideTitle)
				{
					<h1 class="@titleFontSize">@headerName</h1>
				}

				@if (!hideDescription && !string.IsNullOrEmpty(groupDescription))
				{
					<div class="@descriptionFontSize">
						@groupDescription
					</div>
				}
			</div>
		</div>
	}
	else if (Pageview.IsVisualEditorMode)
	{
		<div class="alert alert-dark m-0" role="alert">
			<span>@Translate("Product list info: The info paragraph will be shown here, if any")</span>
		</div>
	}
}
else if (Pageview.IsVisualEditorMode)
{
	<div class="alert alert-dark m-0" role="alert">
		<span>@Translate("Product list info: The info paragraph will be shown here, if any")</span>
	</div>
}

