import { createBrowserRouter } from 'react-router-dom';
import App from '../App';
import Login from '../pages/Login';
import Register from '../pages/Register';
import NotFound from '../pages/NotFound';
import Unauthorized from '../pages/Unauthorized';
import AdminPanel from '../pages/AdminPanel';
import ProtectedRoute from './protectedroute';
import PermissionRoute from './PermissionRoute';

const router = createBrowserRouter([
  {
    path: '/',
    element: (
      <ProtectedRoute>
        <App />
      </ProtectedRoute>
    ),
  },
  {
    path: '/login',
    element: <Login />,
  },
  {
    path: '/register',
    element: <Register />,
  },
  {
    path: '/unauthorized',
    element: <Unauthorized />,
  },
  {
    path: '/admin',
    element: (
      <ProtectedRoute>
        <PermissionRoute requiredRoles={['admin']}>
          <AdminPanel />
        </PermissionRoute>
      </ProtectedRoute>
    ),
  },
  {
    path: '*',
    element: <NotFound />,
  },
]);

export default router;