import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom'
import { TranslationProvider } from '@/contexts/TranslationContext'
import { LanguageProvider } from '@/contexts/LanguageContext'
import { NavigationGuardProvider } from '@/contexts/NavigationGuardContext'
import { WizardProvider } from '@/contexts/WizardContext'
import { AdminLayout } from '@/components/layout/AdminLayout'
import { Dashboard } from '@/pages/Dashboard'
import { Leads } from '@/pages/Leads'
import { LeadDetail } from '@/pages/LeadDetail'
import { Conversations } from '@/pages/Conversations'
import { ConversationDetail } from '@/pages/ConversationDetail'
import { Bots } from '@/pages/Bots'
import { BotDetail } from '@/pages/BotDetail'
import { Personalities } from '@/pages/Personalities'
import { PersonalityDetail } from '@/pages/PersonalityDetail'
import { ContactLists } from '@/pages/ContactLists'
import { Widgets } from '@/pages/Widgets'
import { WidgetDetail } from '@/pages/WidgetDetail'
import { AppearancePresets } from '@/pages/AppearancePresets'
import { AppearancePresetDetail } from '@/pages/AppearancePresetDetail'
import { OpeningScreenPresets } from '@/pages/OpeningScreenPresets'
import { OpeningScreenPresetDetail } from '@/pages/OpeningScreenPresetDetail'
import { WooCommerceSettings } from '@/pages/WooCommerceSettings'
import { WooCommercePresetDetail } from '@/pages/WooCommercePresetDetail'
import { Meetings } from '@/pages/Meetings'
import { Integrations } from '@/pages/Integrations'
import { Settings } from '@/pages/Settings'
import { Analytics } from '@/pages/Analytics'
import { KnowledgeBase } from '@/pages/KnowledgeBase'
import { BrandCard } from '@/pages/BrandCard'
import { UsageDashboard } from '@/pages/UsageDashboard'
import { Updates } from '@/pages/Updates'
import { Support } from '@/pages/Support'
// Feedback is managed centrally on the backend — no local admin page

// Create Query Client with default options
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 30 * 1000, // 30 seconds
      retry: 1,
      refetchOnWindowFocus: false,
    },
  },
})

export function App() {
  
  return (
    <QueryClientProvider client={queryClient}>
      <TranslationProvider>
        <LanguageProvider>
        <HashRouter>
          <NavigationGuardProvider>
          <WizardProvider>
            <AdminLayout>
              <Routes>
            <Route path="/" element={<Dashboard />} />
            <Route path="/leads" element={<Leads />} />
            <Route path="/leads/:id" element={<LeadDetail />} />
            <Route path="/conversations" element={<Conversations />} />
            <Route path="/conversations/:id" element={<ConversationDetail />} />
            <Route path="/bots" element={<Bots />} />
            <Route path="/bots/new" element={<BotDetail />} />
            <Route path="/bots/:id" element={<BotDetail />} />
            <Route path="/personalities" element={<Personalities />} />
            <Route path="/personalities/new" element={<PersonalityDetail />} />
            <Route path="/personalities/:id" element={<PersonalityDetail />} />
            <Route path="/contact-lists" element={<ContactLists />} />
            <Route path="/widgets" element={<Widgets />} />
            <Route path="/widgets/new" element={<WidgetDetail />} />
            <Route path="/widgets/:id" element={<WidgetDetail />} />
            <Route path="/appearance-presets" element={<AppearancePresets />} />
            <Route path="/appearance-presets/new" element={<AppearancePresetDetail />} />
            <Route path="/appearance-presets/:id" element={<AppearancePresetDetail />} />
            <Route path="/opening-screen-presets" element={<OpeningScreenPresets />} />
            <Route path="/opening-screen-presets/new" element={<OpeningScreenPresetDetail />} />
            <Route path="/opening-screen-presets/:id" element={<OpeningScreenPresetDetail />} />
            <Route path="/woocommerce-settings" element={<WooCommerceSettings />} />
            <Route path="/woocommerce-presets/new" element={<WooCommercePresetDetail />} />
            <Route path="/woocommerce-presets/:id" element={<WooCommercePresetDetail />} />
            <Route path="/meetings" element={<Meetings />} />
            <Route path="/analytics" element={<Analytics />} />
            <Route path="/usage" element={<UsageDashboard />} />
            <Route path="/knowledge-base" element={<KnowledgeBase />} />
            <Route path="/brand-card" element={<BrandCard />} />
            <Route path="/integrations" element={<Integrations />} />
            <Route path="/settings" element={<Settings />} />
            {(window as any).boostbotAdmin?.selfHosted && (
              <Route path="/updates" element={<Updates />} />
            )}
            <Route path="/support" element={<Support />} />
            <Route path="*" element={<Navigate to="/" replace />} />
              </Routes>
            </AdminLayout>
          </WizardProvider>
          </NavigationGuardProvider>
        </HashRouter>
        </LanguageProvider>
      </TranslationProvider>
    </QueryClientProvider>
  )
}



