// project import
import LoginRoutes from './LoginRoutes'
import MainRoutes from './MainRoutes'
import {useRoutes} from 'react-router-dom'
import {isUserLoggedIn} from "utils/Utils";
import {Navigate} from "react-router";
import { 
    setupAxiosInterceptors,
    } from "../auth";
import SettingRoutes from './SettingRoutes';
// ==============================|| ROUTING RENDER ||============================== //

export default function ThemeRoutes() {

    if(isUserLoggedIn()){
        //auto logout if token not valid
        setupAxiosInterceptors();
    }

    return useRoutes([{
        path: '',
        children: [
            (isUserLoggedIn() ?
                {
                    path: '',
                    element: <Navigate to="/dashboard"/>
                }
                :
                {
                    path: '',
                    element: <Navigate to="/login"/>
                })
        ]
    },
        isUserLoggedIn() ? MainRoutes : LoginRoutes,
        isUserLoggedIn() ? SettingRoutes : LoginRoutes,
        !isUserLoggedIn()?{
            path: '*',
            element: <Navigate to="/login"/>
        }:
        {
            path: '*',
            element: <Navigate to="/dashboard"/>
        },
    ]);
}
