@inherits ViewModelTemplate<PageViewModel>
@using Dynamicweb
@using Dynamicweb.Environment
@using Dynamicweb.Frontend
@using Dynamicweb.Rendering
@using Dynamicweb.Content

@{
	string? pageId = Dynamicweb.Context.Current?.Request.QueryString.Get("ID");
	string? paragraphId = Dynamicweb.Context.Current?.Request.QueryString.Get("ParagraphID");
	string? rowId = Dynamicweb.Context.Current?.Request.QueryString.Get("RowID");
	string? cacheId = Dynamicweb.Context.Current?.Request.QueryString.Get("cacheId");
	
	var gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page");
	
	@* Swift stylesheet *@
	AddStylesheet("/Files/Templates/Designs/Swift-v2/Assets/css/swift.css");
	
	@* Color schemes stylesheet *@
	if (Model.TryGetColorSchemeStyle(out string? colorSchemeStyle))
	{
		AddStylesheet(colorSchemeStyle);
	}
	@* Button stylesheet *@
	if (Model.TryGetButtonStyle(out string? buttonStyle)) {
		AddStylesheet(buttonStyle);
	}
	@* Typography stylesheet *@
	if (Model.TryGetTypographyStyle(out string? typographyStyle)) {
		AddStylesheet(typographyStyle);
	}
	
	@* Get stylesheets *@
	@Model.GetStylesheetsMarkup()
}

<style>
	.preview { 
		background-color: white; 
		--dw-type-scale: 1.2;

		&:has(.card) {
			width: fit-content;
			margin: auto;	
		}

		&:has(.card):has(img) .card {
			--dw-type-scale: 1.4;
			max-inline-size: none !important;
		}

		[data-swift-poster] {
			--swift-poster-height: 40rem !important;
			--swift-text-width: 100%;
			aspect-ratio: 16/9;
			max-width: 100%;
		}

		h1, .h1, .dw-h1, h2, .h2, .dw-h2, h3, .h3, .dw-h3, h4, .h4, .dw-h4, h5, .h5, .dw-h5, h6, .h6, .dw-h6 {
			margin-block-end: 1rem;
		}

		p, .dw-paragraph {
			line-height: 1.2;
			font-size: calc(var(--dw-font-size) * var(--dw-type-scale));
		}

		.swiffy-slider .card {
			min-height: unset;
			max-height: 40rem;

			img {
				position: relative !important;
			}
		}
		[data-swift-container] {
			--dw-container-width: 100% !important;
			--dw-container-gutter: 0 !important;
		}
	}
</style>

<div class="body preview" data-dw-colorscheme="@(Model.ColorScheme?.Id ?? Model.Area?.ColorScheme?.Id)">
	@if (paragraphId is not null)
	{ 
		Paragraph? paragraph = Dynamicweb.Content.Services.Paragraphs.GetParagraph(Convert.ToInt32(paragraphId));

		<div data-swift-gridcolumn data-dw-itemtype="@paragraph?.Item?.SystemName.ToLower()" id="@paragraph?.ID" data-dw-colorscheme="@paragraph?.ColorSchemeId">
			@RenderParagraphContent(Convert.ToInt32(paragraphId))
		</div>
	}
	else if (rowId is not null) 
	{
		@RenderGridRow(Convert.ToInt32(rowId))
	}
	else if (!string.IsNullOrEmpty(cacheId))
	{ 	
		string? itemTemplate = Dynamicweb.Context.Current?.Request.QueryString.Get("ItemTemplate");
		
		if (Dynamicweb.Caching.Cache.Current.Get(cacheId) is ParagraphViewModel paragraphViewModel && !string.IsNullOrEmpty(paragraphViewModel.ItemType)){
			
			<div data-swift-gridcolumn data-dw-colorscheme="@paragraphViewModel.ColorScheme?.Id">				
				@RenderPartial($"/Paragraph/{paragraphViewModel.ItemType}/{itemTemplate}", paragraphViewModel)
			</div>
		}
	}
	else 
	{
		@gridContent
	}
</div>




