import { getCategories } from '~/apis/common/get-categories'
import { getNews } from '~/apis/common/get-news'
import { NewsPage } from '~/pages/news'

import type { Route } from './+types/_news._index'

export const loader = async ({}: Route.LoaderArgs) => {
  const { data: categoriesData } = await getCategories()
  const spotlightCode = 'spotlight'
  const spotlightCategory = categoriesData.find(
    (category) => category.code === spotlightCode,
  )
  const { data: spotlightNews } = await getNews({ categories: [spotlightCode] })
  const beritaCode = 'berita'
  const beritaCategory = categoriesData.find(
    (category) => category.code === beritaCode,
  )
  const { data: beritaNews } = await getNews({ categories: [beritaCode] })
  return { spotlightCategory, spotlightNews, beritaCategory, beritaNews }
}

const NewsIndexLayout = () => <NewsPage />

export default NewsIndexLayout
