@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb.Ecommerce.ProductCatalog
@using System.Collections.Generic

@functions {

	string GetFieldsFormatted(List<FieldValueViewModel> fields, bool hideLabels)
	{
		List<string> fieldsToRender = new List<string>();

		foreach (var field in fields)
		{

			if (!hideLabels)
			{
				fieldsToRender.Add($"<span>{field.Name}: </span class=\"opacity: 75\"> <span>{RenderPartial("Components/Specifications/Shared/FieldValue.cshtml", field)}</span>");
			}
			else
			{
				fieldsToRender.Add($"<span>{RenderPartial("Components/Specifications/Shared/FieldValue.cshtml", field)}</span>");
			}

		}
		
		string fieldsString = (string.Join(", ", fieldsToRender.Select(x => x.ToString()).ToArray()));
		return fieldsString;
	}
}

@{
	var groups = GetViewParameter("Groups") as List<FieldGroupViewModel>;
	bool hideGroupHeaders = GetViewParameterBoolean("HideGroupHeaders");
	bool hideTitle = GetViewParameterBoolean("HideTitle");
	string size = GetViewParameterString("Size");

	string title = Model.Item.GetString("Title");
	bool hideLabels = Model.Item.GetBoolean("HideFieldLabels");
	string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-4");
	string gapCss = size == "full" ? " gap-4" : " gap-2";

	if (!hideTitle)
	{
		<h2 class="g-col-12 @titleFontSize">@title</h2>
	}

	foreach (var group in groups)
	{

		string fieldsFormatted = GetFieldsFormatted(group.Fields, hideLabels);

		<div class="g-col-12 opacity-75 fs-7 @(gapCss)">
			@if (!hideGroupHeaders)
			{
				<h3>@group.Name</h3>
			}

			@fieldsFormatted
		</div>
	}
}
