import type { NextPage } from 'next';
import React, { useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { MainLayoutRoot } from '../components/admin/pages/Root/Main'
import { Login } from '../components/admin/pages/login/Login';

import { useAppDispatch } from '../redux/store';
import { selectTokenData } from '../redux/login/selectors';

const Admin: NextPage = () => {
  const dispatch = useAppDispatch();
  const [login, setLogin] = useState<boolean>(false);
  const { token, status_token } = useSelector(selectTokenData);


  function replacer(key:string, value:string) {
    console.log(typeof value);
    if (key === 'token') {
      setLogin(true);
      console.log(value)
    } else {console.log(key)}
  }

 if (status_token === 'completed_token') {
  JSON.stringify(token, replacer);

}
useEffect(() => {
    if (localStorage.getItem("token") || '') {
      setLogin(true);
    } else { setLogin(false) }
}, [1]);



  return (
       <>{login ? <MainLayoutRoot/> : <Login/>}</>
  )
}

export default Admin;
