import { BadgeCheck, Building2, Key, KeyRound, LayoutDashboard, LogOut, Moon, NotebookTabs, ShieldHalf, Sun, Users, } from "lucide-react"; import { useEffect, useState } from "react"; import { useAuth } from "react-oidc-context"; import { NavLink, Outlet, useNavigate } from "react-router-dom"; import { t } from "../../lib/i18n"; import LanguageSelector from "../common/LanguageSelector"; import RoleSwitcher from "./RoleSwitcher"; const navItems = [ { label: "ui.admin.nav.overview", to: "/", icon: LayoutDashboard }, { label: "ui.admin.nav.tenant_dashboard", to: "/dashboard", icon: ShieldHalf, }, { label: "ui.admin.nav.tenants", to: "/tenants", icon: Building2, }, { label: "ui.admin.nav.users", to: "/users", icon: Users }, { label: "ui.admin.nav.api_keys", to: "/api-keys", icon: Key }, { label: "ui.admin.nav.audit_logs", to: "/audit-logs", icon: NotebookTabs }, { label: "ui.admin.nav.auth_guard", to: "/auth", icon: KeyRound }, ]; function AppLayout() { const auth = useAuth(); const navigate = useNavigate(); const [theme, setTheme] = useState<"light" | "dark">(() => { const stored = window.localStorage.getItem("admin_theme"); return stored === "dark" ? "dark" : "light"; }); const handleLogout = () => { if ( window.confirm(t("msg.admin.logout_confirm", "로그아웃 하시겠습니까?")) ) { window.localStorage.removeItem("admin_session"); auth.removeUser(); navigate("/login"); } }; useEffect(() => { if (!auth.isLoading && !auth.isAuthenticated) { navigate("/login"); } }, [auth.isLoading, auth.isAuthenticated, navigate]); useEffect(() => { const root = document.documentElement; root.classList.remove("light", "dark"); if (theme === "light") { root.classList.add("light"); } else { root.classList.add("dark"); } window.localStorage.setItem("admin_theme", theme); }, [theme]); const toggleTheme = () => { setTheme((prev) => (prev === "light" ? "dark" : "light")); }; if (auth.isLoading) { return (
{t("ui.admin.header.plane", "Admin Plane")}
{t( "msg.admin.header.subtitle", "Tenant isolation & least privilege by default", )}