import type { NextPage } from 'next';
import React, { useState, useEffect } from 'react';

import Router from "next/router";
import { useSelector } from 'react-redux';
import { MainLayoutRoot } from '../../components/admin/pages/Root/Main'
import { Login } from './login';

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

const Admin: NextPage = () => {

  const [login, setLogin] = useState<boolean>(false);
  const { status_token } = useSelector(selectTokenData);

  useEffect(() => {
    localStorage.getItem("token") ? setLogin(true) : setLogin(false);
  }, [status_token]);

  return (
       <>{login ?  Router.replace('/admin/main'): Router.replace('/admin/login') }</>
  )
}

export default Admin;
