import { createBrowserRouter, Navigate } from 'react-router-dom'
import { Layout } from './components/Layout'
import { AuthGuard } from './components/AuthGuard'
import { Login } from './pages/Login'
import { Dashboard } from './pages/Dashboard'
import { Users } from './pages/Users'
import { Profile } from './pages/Profile'

export const router = createBrowserRouter([
  { path: '/login', element: <Login /> },
  {
    path: '/',
    element: (
      <AuthGuard requireAuth>
        <Layout />
      </AuthGuard>
    ),
    children: [
      { index: true, element: <Dashboard /> },
      {
        path: 'users',
        element: (
          <AuthGuard allowedRoles={['admin', 'system_admin']} requireAuth>
            <Users />
          </AuthGuard>
        ),
      },
      {
        path: 'profile',
        element: <Profile />,
      },
    ],
  },
  { path: '*', element: <Navigate to="/" replace /> },
])
