import React, { lazy, useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { Navigate, useRoutes } from 'react-router'
import DashboardLayout from '../components/DashboardLayout'
import { Dispatch } from '../models/store'
import LoginPage from './Login/index1'




const HomePage = lazy(() => import('./Home'))


const AppRouters: React.FC = () => {
  const dispatch = useDispatch<Dispatch>()

  useEffect(() => {
    ;(window as any).__dispatch__ = dispatch
    return () => {
      delete (window as any).__dispatch__
    }
  }, [dispatch])

  let element = useRoutes([
    { path: '/', element: <LoginPage /> },
    {
      path: '/mgr',
      element: <DashboardLayout />,
      children: [
        { path: 'home', element: <HomePage /> },


        
      ],
    },
    { path: '/login', element: <LoginPage /> },
  ])

  return element
}

export default AppRouters
