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

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: GetServerSideProps<Props> = async function (ctx) {
  const user = await parseUser(ctx);
  const isDashboardPage = ["/guilds", "/dashboard"].includes(ctx.resolvedUrl);

  if (!user && isDashboardPage) {
    return {
      redirect: {
        destination: "/api/oauth",
        permanent: false,
      },
    };
  }

  return { props: { user } };
};


export default Index;
