import { HashRouter, Routes, Route, Navigate } from 'react-router-dom'
import Login from '@/pages/Login'
import MainLayout from '@/layouts/MainLayout'
import AssetLibrary from '@/pages/assets/AssetLibrary'
import UploadResource from '@/pages/assets/UploadResource'
import ProjectLibrary from '@/pages/projects/ProjectLibrary'
import NewProject from '@/pages/projects/NewProject'
import ProfilePage from '@/pages/ProfilePage'
import FileLibrary from '@/pages/files/FileLibrary'
import { ToastProvider } from '@/components/ui/toast-provider'

import { DownloadManagerProvider } from '@/components/DownloadManager'

// 其他页面的占位符，以避免演示期间出现 404
const PlaceholderPage = ({ title }: { title: string }) => (
  <div className="flex items-center justify-center h-full text-slate-400">
    <div className="text-center">
      <h2 className="text-2xl font-bold mb-2">{title}</h2>
      <p>功能开发中...</p>
    </div>
  </div>
)

function App() {
  return (
    <ToastProvider>
      <DownloadManagerProvider>
        <HashRouter>
          <Routes>
            <Route path="/" element={<Login />} />
            {/* Full width pages with Header but no Sidebar */}
            <Route element={<MainLayout showSidebar={false} />}>
              <Route path="/upload" element={<UploadResource />} />
              <Route path="/profile" element={<ProfilePage />} />
              <Route path="/app/projects/new" element={<NewProject />} />
            </Route>

            {/* Main Application Routes */}
            <Route path="/app" element={<MainLayout />}>
              <Route index element={<Navigate to="/app/plugins" replace />} />
              <Route path="plugins" element={<AssetLibrary />} />
              <Route path="components" element={<PlaceholderPage title="组件库" />} />
              <Route path="tools" element={<PlaceholderPage title="工具库" />} />
              <Route path="prototypes" element={<PlaceholderPage title="原型库" />} />
              <Route path="design" element={<PlaceholderPage title="设计库" />} />
              <Route path="projects" element={<ProjectLibrary />} />
              <Route path="files" element={<FileLibrary />} />
              <Route path="cases" element={<PlaceholderPage title="案例库" />} />
              <Route path="pending" element={<PlaceholderPage title="待审核" />} />
            </Route>

            {/* Legacy/Redirects */}
            <Route path="/dashboard" element={<Navigate to="/app" replace />} />
          </Routes>
        </HashRouter>
      </DownloadManagerProvider>
    </ToastProvider>
  )
}


export default App
