
import * as React from "react";
import * as HttpUtils from "utils/HttpUtils";
import * as UrlUtils from "utils/ApiPathConst";
import { useNavigate } from "react-router-dom";
import Loadable from 'components/Loadable';
const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
import {
    Grid,
} from '@mui/material';

// ==============================|| DASHBOARD - DEFAULT ||============================== //

const Index = () => {

    const navigate = useNavigate()

    React.useEffect(() => {
        getPrfile();
    }, []);

    function getPrfile(){
        let params = new URLSearchParams(window.location.search)
        if(params.get("code")){
            HttpUtils.post({
                url: UrlUtils.GET_SMART_PROFILE,
                params:{
                    code: params.get("code")
                },
                onSuccess: (responseData) => {
                    navigate('/iAmSmartRegisterFrom', { state: { responseData: responseData } });
                },
                onFail: (response)=>{
                    console.log("Fail");
                    console.log(response);
                    window.location.assign("/register");
                },
                onError:(error)=>{
                    console.log(error);
                    window.location.assign("/register");
                }
            });
        }else{
            window.location.assign("/register");
        }
    }

    return (
        <Grid container sx={{ minHeight: '95vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
            <Grid item>
                <LoadingComponent />
            </Grid>
        </Grid>
    );
};

export default Index;