import React, { useEffect, useState } from 'react'
import { useLocation, useNavigate, Outlet } from 'react-router-dom'
import Layout from '../components/layout/Layout'

import myLinks from '../myLinks'
import PageLoader from '../components/PageLoader'

export default function UserExists() {

    const {state} = useLocation()

    const navigate = useNavigate()
  
    const [loading, setLoading] = useState(true)
  
    useEffect(()=>{
      if(!state || localStorage.getItem('active') != 'true'){
        return navigate(myLinks.getStarted, {replace:true})
      }
      setTimeout(()=>{
        setLoading(false)
      },2000)
    },[])

  return (
    <>
    {
    loading ? 
        <PageLoader />
        :
        <Layout>
          <Outlet />
        </Layout>
    }
    </>
  )
}
