import {BrowserRouter, Routes, Route} from 'react-router-dom';
import { createTheme, ThemeProvider, CssBaseline } from '@mui/material';
import { AuthProvider } from './context/AuthContext';
import PrivateRoute from './components/PrivateRoute';
import Layout from './components/Layout';
import LoginPage from './pages/Auth/LoginPage.jsx';
import RegisterPage from './pages/Auth/RegisterPage.jsx';
import UsersPage from './pages/Auth/UsersPage.jsx';
import PostsPage from './pages/News/PostsPage.jsx';
import CreateNewsPage from './pages/News/CreateNewsPage.jsx';
import OrganizationPage from './pages/Organization/OrganizationPage.jsx';
import PushPage from './pages/Notification/PushPage.jsx';
import EditAttractionPage from './pages/Attraction/EditAttractionPage.jsx';
import AttractionPage from './pages/Attraction/AttractionPage.jsx';
import HomePage from './pages/Home/HomePage.jsx';
import EditOrganizationPage from "./pages/Organization/EditOrganizationPage.jsx";
import CompanyPage from "./pages/Company/CompanyPage.jsx";
import EditCompanyPage from "./pages/Company/EditCompanyPage.jsx";
import CalenderPostPage from "./pages/Calender/CalenderPostPage.jsx";
import ProfilePage from "./pages/Auth/ProfilePage.jsx";
import UnauthorizedPage from "./pages/Auth/UnauthorizedPage.jsx";
import DatenschutzPage from "./pages/Legal/DatenschutzPage.jsx";
import ImpressumPage from "./pages/Legal/ImpressumPage.jsx";



const theme = createTheme({
    palette: {
        mode: 'light',
        primary: { main: '#1976d2' },
        background: { default: '#f5f5f5' },
    },
    shape: { borderRadius: 8 },
    typography: {
        fontFamily: '"Inter", "Roboto", "Helvetica", "Arial", sans-serif',
    },
    components: {
        MuiButton: {
            styleOverrides: {
                root: { textTransform: 'none', fontWeight: 500 },
            },
        },
        MuiCard: {
            styleOverrides: {
                root: { boxShadow: '0 1px 3px rgba(0,0,0,0.08)', border: '1px solid #e0e0e0' },
            },
        },
    },
});

export default function App() {
    return (
        <ThemeProvider theme={theme}>
            <CssBaseline />
            <AuthProvider>
                <BrowserRouter>
                    <Routes>
                        <Route path="/login" element={<LoginPage />} />
                        <Route path="/impressum" element={<ImpressumPage />} />
                        <Route path="/datenschutz" element={<DatenschutzPage />} />
                        <Route path="/register" element={<RegisterPage />} />
                        <Route path="/unauthorized" element={<UnauthorizedPage />} />  {/* ← neu */}
                        <Route
                            path="/"
                            element={
                                <PrivateRoute>
                                    <Layout />
                                </PrivateRoute>
                            }
                        >
                            <Route
                                index
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER', 'SITE_OWNER']}>
                                        <HomePage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="users"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN']}>
                                        <UsersPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="attractions"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER']}>
                                        <AttractionPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="profile"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER', 'SITE_OWNER']}>
                                        <ProfilePage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="calenderPosts"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER']}>
                                        <CalenderPostPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="posts"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER']}>
                                        <PostsPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="companies"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'SITE_OWNER']}>
                                        <CompanyPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="attractions/:id/edit"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER']}>
                                        <EditAttractionPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="companies/:id/edit"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'SITE_OWNER']}>
                                        <EditCompanyPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="organizations/:id/edit"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'SITE_OWNER']}>
                                        <EditOrganizationPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="organizations"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'SITE_OWNER']}>
                                        <OrganizationPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="posts/create"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN', 'REPORTER']}>
                                        <CreateNewsPage />
                                    </PrivateRoute>
                                }
                            />
                            <Route
                                path="push"
                                element={
                                    <PrivateRoute allowedRoles={['ADMIN']}>
                                        <PushPage />
                                    </PrivateRoute>
                                }
                            />
                        </Route>
                    </Routes>
                </BrowserRouter>
            </AuthProvider>
        </ThemeProvider>
    );
}