@page "/archive/featured"

@using Microsoft.EntityFrameworkCore
@using Microsoft.Extensions.Logging
@using MudBlazor
@using NpgsqlTypes
@using OpenArchival.DataAccess
@using Persic
@using Npgsql.EntityFrameworkCore.PostgreSQL
@using System.Linq
@using System.Linq.Expressions

@using OpenArchival.Blazor.ArtifactGroupingDisplay
@using OpenArchival.Blazor.ArchiveSearch

@namespace OpenArchival.Blazor.ArchiveDisplay

<MudText Typo="Typo.h2" Color="Color.Primary" Align="Align.Center">Featured Artifacts</MudText>
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" Href="/search">See All Artifacts</MudButton>

@foreach (SearchPageSliderEntry entry in _sliderEntries)
{
    <SearchPageSlider SliderEntry="entry"></SearchPageSlider>
}

@inject IDbContextFactory<ApplicationDbContext> ContextFactory;
@inject ILogger<SearchArchive> Logger;
@inject NavigationManager NavigationManager;

@code {
    [Parameter]
    public string SearchTerms { get; set; } = "";

    private List<SearchPageSliderEntry> _sliderEntries { get; set; } = [];

    // Field to store the current filter logic
    private Expression<Func<ArtifactGrouping, bool>> _currentFilterPredicate;

    protected override async Task OnParametersSetAsync()
    {
        await using var context = await ContextFactory.CreateDbContextAsync();
        _sliderEntries = await context.SearchPageSliderEntries.Include(e => e.FilterTags).ToListAsync();
    }
}