import { getArticles } from '@/lib/content/awq/articles'
import { getTalents } from '@/lib/content/awq/talents'
import { cache } from 'react'

export const collectAWQContent = cache(async () => {
  const [articles, talents] = await Promise.all([getArticles(), getTalents()])

  return [
    ...articles.map((item) => ({
      ...item.entry,
      slug: item.slug,
      type: 'article',
      fullPath:
        item.slug === 'index'
          ? item.entry.path
          : item.entry.path
            ? `${item.entry.path}/${item.slug}`
            : item.slug,
    })),
    ...talents.map((item) => ({
      ...item.entry,
      slug: item.slug,
      type: 'talent',
      fullPath: item.entry.path ? `${item.entry.path}/${item.slug}` : item.slug,
    })),
  ]
})

export const getContentByPath = cache(async (path: string) => {
  const allContent = await collectAWQContent()
  return allContent.find((item) => item.fullPath === path)
})
