@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.QueryPublisher.QueryResultViewModel>
@using Dynamicweb.Core.Encoders
@using Dynamicweb
@using Dynamicweb.Frontend

<div data-swift-posts-list>
	@if (Model.Results.Count() > 0)
	{
		<div class="grid gap-3">
			@foreach (var post in Model.Results)
			{
				if (post.TryGetValue("PageId", out object? pageId) && pageId is int)
				{
					var pageInfo = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Dynamicweb.Content.Services.Pages?.GetPage((int)pageId));

					if (pageInfo != null)
					{
						<a href="/Default.aspx?ID=@pageInfo.ID" class="g-col-12 card text-decoration-none" style="min-height: 7rem;">
							<div class="grid gap-0 h-100">
								@if (pageInfo.TryGetImageFile(out ImageFileViewModel imageFile))
								{
									<div class="g-col-3 h-100 p-2">
										<img src="@imageFile.ToGetImage(new GetImageSettings { Ratio = "4/3" })" class="img-fluid h-100 object-fit-cover" alt="@pageInfo.Name">
									</div>
								}
								<div class="g-col-9">
									<div class="card-body p-2 h-100 d-flex flex-column" style="max-width: 100%;">
										<div class="flex-fill mb-2">
											<h5 class="card-title mb-2">
												@pageInfo.Name
											</h5> 
											<p class="card-text fs-7 overflow-hidden" style="white-space: nowrap; text-overflow: ellipsis;">
												@pageInfo.Description
											</p>
										</div>
										<div>
											<div class="opacity-75 fs-8">@pageInfo.CreatedDate.ToShortDateString()</div>
										</div>
									</div>
								</div>
							</div>
						</a>
					}
				}
			}
		</div>

		@RenderPartial("Designs/Swift-v2/QueryPublisher/Post/PostPagination.cshtml")
	}
	else
	{
		<div class="alert alert-dark w-100 text-center" role="alert">
			@Translate("No results found")
		</div>
	}
</div>