import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { BrowserRouter, Route, Routes } from 'react-router-dom'
import { Layout } from './components/Layout'
import { Dashboard } from './pages/Dashboard'
import { GenerateCalendar } from './pages/GenerateCalendar'
import { GenerateSingle } from './pages/GenerateSingle'
import { OutputReview } from './pages/OutputReview'
import { PromptEditor } from './pages/PromptEditor'
import { Settings } from './pages/Settings'

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retry: 1,
      staleTime: 30_000,
    },
  },
})

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      {/* basename must match the nginx subpath and Vite base config */}
      <BrowserRouter basename="/postgenerator">
        <Layout>
          <Routes>
            <Route path="/" element={<Dashboard />} />
            <Route path="/genera" element={<GenerateCalendar />} />
            <Route path="/genera-singolo" element={<GenerateSingle />} />
            <Route path="/risultati/:jobId" element={<OutputReview />} />
            <Route path="/prompt-editor" element={<PromptEditor />} />
            <Route path="/impostazioni" element={<Settings />} />
          </Routes>
        </Layout>
      </BrowserRouter>
    </QueryClientProvider>
  )
}

export default App
