import { getCollection } from '$lib/utils/payload'
import type { PageLoad } from './$types'
import type { NeuigkeitenPost } from '$lib/types/neuigkeiten'

export const load: PageLoad = async ({ fetch }) => {
    const { docs: posts } = await getCollection<NeuigkeitenPost>('neuigkeiten', {
        sort: '-publishedAt',
        where: { _status: { equals: 'published' } },
        select: {
            title: true,
            slug: true,
            excerpt: true,
            publishedAt: true,
            featuredImage: true,
        },
    }, fetch)

    return { posts }
}