import {BrowserRouter, Routes, Route} from 'react-router-dom';
import {LoginView, DashboardView, ChannelsView, TestView} from 'views';
import {ProtectedRoute, QueryPreservingRedirect} from 'components';

export default function Router() {
  return (
    <BrowserRouter>
      <Routes>
        {/* Public routes */}
        <Route path="/login" element={<LoginView />} />

        {/* Test route for debugging query parameters */}
        <Route path="/test" element={<TestView />} />

        {/* Protected routes - require authentication */}
        <Route
          path="/dashboard"
          element={
            <ProtectedRoute>
              <DashboardView />
            </ProtectedRoute>
          }
        />

        <Route
          path="/channels"
          element={
            <ProtectedRoute>
              <ChannelsView />
            </ProtectedRoute>
          }
        />

        {/* Default redirects with query parameter preservation */}
        <Route path="/" element={<QueryPreservingRedirect to="/dashboard" />} />
        <Route path="*" element={<QueryPreservingRedirect to="/dashboard" />} />
      </Routes>
    </BrowserRouter>
  );
}
