import { Outlet } from 'react-router'

import { NewsProvider } from '~/contexts/news'
import { NewsDefaultLayout } from '~/layouts/news/default'
import { handleCookie } from '~/libs/cookies'

import type { Route } from './+types/_layout'

export const loader = async ({ request }: Route.LoaderArgs) => {
  const { userToken } = await handleCookie(request)

  return {
    userToken,
  }
}

const NewsLayout = () => {
  return (
    <NewsProvider>
      <NewsDefaultLayout>
        <Outlet />
      </NewsDefaultLayout>
    </NewsProvider>
  )
}

export default NewsLayout
