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

@attribute [Authorize(Policy = "ArticleDeletePermissions")]
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
@inject IStringLocalizer<Future> 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();

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