import { Routes, Route, Navigate } from 'react-router-dom';
import LoginPage from '@/pages/LoginPage';
import MainLayout from '@/layouts/MainLayout';
import Dashboard from '@/pages/Dashboard';
import AgentList from '@/pages/org/AgentList';
import ContractList from '@/pages/product/ContractList';
import RecruitLedger from '@/pages/ledger/RecruitLedger';
import SettleList from '@/pages/settle/SettleList';

function RequireAuth({ children }: { children: React.ReactNode }) {
  const token = localStorage.getItem('accessToken');
  return token ? <>{children}</> : <Navigate to="/login" replace />;
}

export default function App() {
  return (
    <Routes>
      <Route path="/login" element={<LoginPage />} />
      <Route path="/" element={<RequireAuth><MainLayout /></RequireAuth>}>
        <Route index element={<Dashboard />} />
        <Route path="org/agents" element={<AgentList />} />
        <Route path="contracts" element={<ContractList />} />
        <Route path="ledger/recruit" element={<RecruitLedger />} />
        <Route path="settle" element={<SettleList />} />
      </Route>
    </Routes>
  );
}
