import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import Layout from './components/Layout'
import Login from './pages/Login'
import Dashboard from './pages/Dashboard'
import GatewayList from './pages/GatewayList'
import SignBoardList from './pages/SignBoardList'
import AlarmList from './pages/AlarmList'
import RegionList from './pages/RegionList'
import StoreList from './pages/StoreList'
import StoreGroupList from './pages/StoreGroupList'
import TenantList from './pages/TenantList'
import UserList from './pages/UserList'
import TemplateList from './pages/TemplateList'
import SignImageEditor from './pages/SignImageEditor'
import TemplateGroupList from './pages/TemplateGroupList'
import AdScheduleList from './pages/AdScheduleList'
import SignDeployList from './pages/SignDeployList'
import FirmwareList from './pages/FirmwareList'
import BackupList from './pages/BackupList'
import AiAssistant from './pages/AiAssistant'
import AiPlatformSettings from './pages/AiPlatformSettings'
import AuditLog from './pages/AuditLog'
import SystemSettings from './pages/SystemSettings'

const qc = new QueryClient()

export default function App() {
  return (
    <QueryClientProvider client={qc}>
      <BrowserRouter>
        <Routes>
          <Route path="/login" element={<Login />} />
          <Route element={<Layout />}>
            <Route path="/dashboard"       element={<Dashboard />} />
            <Route path="/gateways"        element={<GatewayList />} />
            <Route path="/signboards"      element={<SignBoardList />} />
            <Route path="/alarms"          element={<AlarmList />} />
            <Route path="/regions"         element={<RegionList />} />
            <Route path="/stores"          element={<StoreList />} />
            <Route path="/store-groups"    element={<StoreGroupList />} />
            <Route path="/tenants"         element={<TenantList />} />
            <Route path="/users"           element={<UserList />} />
            <Route path="/templates"       element={<TemplateList />} />
            <Route path="/sign-editor"     element={<SignImageEditor />} />
            <Route path="/template-groups" element={<TemplateGroupList />} />
            <Route path="/ad-schedules"    element={<AdScheduleList />} />
            <Route path="/deploys"         element={<SignDeployList />} />
            <Route path="/firmware"        element={<FirmwareList />} />
            <Route path="/backups"         element={<BackupList />} />
            <Route path="/ai"              element={<AiAssistant />} />
            <Route path="/ai-platform"     element={<AiPlatformSettings />} />
            <Route path="/audit"           element={<AuditLog />} />
            <Route path="/settings"        element={<SystemSettings />} />
          </Route>
          <Route path="*" element={<Navigate to="/dashboard" replace />} />
        </Routes>
      </BrowserRouter>
    </QueryClientProvider>
  )
}
