import { createBrowserRouter, Navigate } from 'react-router-dom';
import AdminLayout from '../components/AdminLayout';
import PlayerLayout from '../components/PlayerLayout';
import AdminAuthRoute from '../components/AdminAuthRoute';
import PlayerAuthRoute from '../components/PlayerAuthRoute';
import AdminLogin from '../pages/admin/AdminLogin';
import AdminDashboard from '../pages/admin/AdminDashboard';
import AdminUsers from '../pages/admin/AdminUsers';
import PlayerLogin from '../pages/player/PlayerLogin';
import PlayerDashboard from '../pages/player/PlayerDashboard';

const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/player/login" replace />,
  },
  {
    path: '/admin',
    children: [
      {
        path: 'login',
        element: <AdminLogin />,
      },
      {
        element: <AdminAuthRoute />,
        children: [
          {
            element: <AdminLayout />,
            children: [
              {
                path: 'dashboard',
                element: <AdminDashboard />,
              },
              {
                path: 'users',
                element: <AdminUsers />,
              },
              {
                index: true,
                element: <Navigate to="/admin/dashboard" replace />,
              },
            ],
          },
        ],
      },
    ],
  },
  {
    path: '/player',
    children: [
      {
        path: 'login',
        element: <PlayerLogin />,
      },
      {
        element: <PlayerAuthRoute />,
        children: [
          {
            element: <PlayerLayout />,
            children: [
              {
                path: 'dashboard',
                element: <PlayerDashboard />,
              },
              {
                index: true,
                element: <Navigate to="/player/dashboard" replace />,
              },
            ],
          },
        ],
      },
    ],
  },
]);

export default router;
