@page "/review"
@using Wave.Data
@using Microsoft.EntityFrameworkCore

@attribute [Authorize(Policy = "ArticleReviewPermissions")]
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
@inject IStringLocalizer<Review> Localizer

<PageTitle>@(Localizer["Title"] + TitlePostfix)</PageTitle>

<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"]</h1>
<ArticleCardList Articles="Articles" />

@code {
	[CascadingParameter(Name = "TitlePostfix")]
	private string TitlePostfix { get; set; } = default!;
	private List<Article> Articles { get; } = [];

	protected override async Task OnInitializedAsync() {
		await using var context = await ContextFactory.CreateDbContextAsync();

		Articles.AddRange(await
			context.Set<Article>()
				.IgnoreQueryFilters()
				.Include(a => a.Author)
				.Include(a => a.Categories)
				.Where(a => !a.IsDeleted && a.Status == ArticleStatus.InReview)
				.OrderByDescending(a => a.PublishDate)
				.ToListAsync());
	}
}
