import { unstable_cache } from 'next/cache'
import { getPayload } from 'payload'
import config from '@/payload.config'
import { Menu } from '@/payload-types'

export const fetchMenu = unstable_cache(
  async (): Promise<Menu> => {
    const payload = await getPayload({ config })
    return payload.findGlobal({ slug: 'menu' })
  },
  ['menu'],
  { tags: ['menu'] },
)
