// material-ui
import {
    Grid,
    Typography,
    Stack,
    Button
} from '@mui/material';
import * as React from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { useLocation } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import Loadable from 'components/Loadable';
const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
import AccountCircleIcon from '@mui/icons-material/AccountCircle';

import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
const BackgroundHead = {
    backgroundImage: `url(${titleBackgroundImg})`,
    width: '100%',
    height: '100%',
    backgroundSize: 'contain',
    backgroundRepeat: 'no-repeat',
    backgroundColor: '#0C489E',
    backgroundPosition: 'right'
}

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

const Index = () => {
    const intl = useIntl();
    const location = useLocation();
    const navigate = useNavigate()
    const [onReady, setOnReady] = React.useState(false);

    React.useEffect(() => {
        if ("iAmSmart" == location?.state?.registryMethod) {
            setOnReady(true);
        } else {
            //setOnReady(true);
            navigate('/login');
        }
    }, []);

    return (
        !onReady ?
            <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
                <Grid item>
                    <LoadingComponent />
                </Grid>
            </Grid>
            :
            <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
                <Grid item xs={12} width="100%">
                    <div style={BackgroundHead} width="100%">
                        <Stack direction="row" height='70px'>
                            <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
                                <FormattedMessage id="pleaseLloginMessage1" />
                            </Typography>
                        </Stack>
                    </div>
                </Grid>
                {/*row 1*/}
                <Grid item xs={12} md={12} >
                    <Grid container justifyContent="flex-start" alignItems="center" >
                        <center>
                        <AccountCircleIcon color="secondary" sx={{ width: "200px", height: "200px" }} />
                            <Grid item xs={12} md={12} >
                                <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
                                    <div dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: 'pleaseLloginMessage2' }) }} />
                                </Typography>
                            </Grid>
                        </center>
                    </Grid>
                </Grid>
                {/*row 2*/}
                <Grid item xs={12} md={12} >
                    <Grid container justifyContent="flex-start" alignItems="center" >
                        <center>
                            <Button
                                component="span"
                                variant="contained"
                                size="large"
                                sx={{ m: 4 }}
                                onClick={() => {
                                    navigate("/login");
                                }}
                            >
                                <FormattedMessage id="pleaseLloginMessage3" />
                            </Button>
                        </center>
                    </Grid>
                </Grid>
            </Grid >


    );
};

export default Index;
