import type { NextPage, GetServerSideProps } from 'next';
import React, { useState, useEffect } from 'react';
import { DiscordUser } from "../../utils/types";
import withSession from '../lib/session'

import {
  BrowserRouter,
  Routes,
  Route,
} from "react-router-dom";
import { useRouter } from 'next/router'
import { useSelector } from 'react-redux';
import { Main } from './main'
import { Login } from './login';

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

const Index: NextPage = () => {
  const router = useRouter();
  const { token, status_token } = useSelector(selectTokenData);
  const [login, setLogin] = useState(false);

  useEffect(() => {
   // token.length ? router.push('/admin/main'): router.push('/admin/login')
    console.log(status_token, 'token');
   //setLogin(true);

  });

  return (
   <></>
  )
}

interface Props {
  user: DiscordUser;
}

export const getServerSideProps = withSession(async function ({ req, res }) {
  const { user } = req.session

  if (!user) {
    return {
      redirect: {
        destination: '/login',
        permanent: false,
      },
    }
  }

  return {
    props: { user },
  }
})


export default Index;
