import { NavLink, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { useAuth } from "./auth";
import Icon from "./components/Icon";
import ErrorBoundary from "./components/ErrorBoundary";
import BrandMark from "./components/BrandMark";
import Login from "./pages/Login";
import ChangePassword from "./pages/ChangePassword";
import Dashboard from "./pages/Dashboard";
import Accounts from "./pages/Accounts";
import Categories from "./pages/Categories";
import Transactions from "./pages/Transactions";
import Budget from "./pages/Budget";
import Import from "./pages/Import";
import Offen from "./pages/Offen";
import Users from "./pages/Users";
import Settings from "./pages/Settings";
import TwoFactor from "./pages/TwoFactor";
import Account from "./pages/Account";
const navClass = ({ isActive }) => (isActive ? "nav-link active" : "nav-link");
function NavItem({ to, icon, label, end }) {
return (
{label}
);
}
function Sidebar() {
const { user, isAdmin, logout } = useAuth();
const { t } = useTranslation();
const navigate = useNavigate();
async function handleLogout() {
await logout();
navigate("/login");
}
return (
);
}
/** Server nicht erreichbar – die Anmeldung bleibt bestehen, nur der Abruf nicht. */
function StartFehler({ text, erneut }) {
const { t } = useTranslation();
return (
{text}
{t("server.sessionKept")}
{t("common.retry")}
);
}
function Protected({ children, adminOnly = false, wide = false }) {
const { user, isAdmin, loading, startFehler, erneutVersuchen } = useAuth();
const { pathname } = useLocation();
const { t } = useTranslation();
if (loading) return {t("common.loading")}
;
if (startFehler) return ;
if (!user) return ;
// Offene Pflichten der Reihe nach – dieselbe Reihenfolge erzwingt der Server
// (backend/app/deps.py, enforce_account_state), sonst liefe man in 403er.
if (user.must_change_password && pathname !== "/passwort-aendern") {
return ;
}
if (user.mfa_setup_required && pathname !== "/zwei-faktor") {
return ;
}
if (adminOnly && !isAdmin) return ;
return (
);
}
export default function App() {
const { user, loading } = useAuth();
return (
: }
/>
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
);
}