import { Blog } from '@/payload-types'
import { PaginatedDocs } from 'payload'
import { stringify } from 'qs-esm'

export const fetchBlog = async (): Promise<PaginatedDocs<Blog> | undefined> => {
  const stringifiedQuery = stringify(
    {
      sort: "-date",
      select: {
        title: true,
        date: true,
        photo: true
      },
      limit: 18
    },
    { addQueryPrefix: true },
  )

  const resp = await fetch(`http://localhost:3000/api/blog`);
  if (!resp.ok) return undefined;
  return resp.json();
}