import React from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';

import UserLayout from '../../components/layout/user/UserLayout';
import NotFound from './NotFound';

import Dashboard from './dashboard/views/Dashboard';
import Learning from './learning/views/Learning';
import Setting from './setting/views/Setting';

import Topic from './topic/views/Topic';
import Level from './level/views/Level';
import Exercise from './exercise/views/Exercise';
import ExerciseResult from './exercise/views/ExerciseResult';
import ExerciseHistory from './history/views/ExerciseHistory';
import Review from './review/views/Review';
import Material from './material/views/Material';

import ProtectedRoute from '../../utils/ProtectedRoute';
import { SlugProvider } from '../../utils/SlugContext';

import '../../assets/styles/user.css';
import useAuth from '../guest/auth/hooks/useAuth';

const UserRoutes = () => {
  const { logout } = useAuth();
  return (
    <SlugProvider logout={logout}>
      <UserLayout>
        <Routes>
          <Route element={<ProtectedRoute role="student" />}>
            <Route path="*" element={<NotFound/>} />
            
            <Route path="/" element={<Navigate to="home" replace />} />
            <Route path="home" element={<Dashboard />} />
            <Route path="module" element={<Learning />} />
            <Route path="setting" element={<Setting />} />
            <Route path="history" element={<ExerciseHistory />} />
            <Route path="review/:stdLearning" element={<Review />} />

            <Route path="module/:section" element={<Topic />} />
            <Route path="module/:section/:topic" element={<Level />} />
            <Route path="module/:section/:topic/:level" element={<Navigate to="material" replace />} />
            <Route path="module/:section/:topic/:level/material" element={<Material />} />
            <Route path="module/:section/:topic/:level/exercise" element={<Exercise />} />
            <Route path="module/:section/:topic/:level/result" element={<ExerciseResult />} />
          </Route>
        </Routes>
      </UserLayout>
    </SlugProvider>
  );
};

export default UserRoutes;
