import { useMemo } from 'react'
import { useLocation } from 'react-router-dom'

import PostImportReviewPage from '@/pages/posts/PostImportReviewPage'
import PostImportSourcePage from '@/pages/posts/PostImportSourcePage'
import { hasPostNewReviewState } from '@/lib/postNewQueryState'

import type { FC } from 'react'

import type { User } from '@/types'

type Props = { user: User | null }


const PostNewPage: FC<Props> = ({ user }) => {
  const location = useLocation ()
  const reviewMode = useMemo (
      () => hasPostNewReviewState (location.search),
      [location.search])

  return reviewMode
      ? <PostImportReviewPage user={user}/>
      : <PostImportSourcePage user={user}/>
}

export default PostNewPage
