'use client' import Link from 'next/link' import { usePathname } from 'next/navigation' import { useEffect, useState } from 'react' import { AdminLanguageSwitcher, AdminThemeSwitcher, useAdminI18n, } from '@/components/I18nProvider' import { resolveBrowserAppUrl } from '@/lib/appUrls' function buildUnifiedLoginUrl(nextPath: string) { const dashboardUrl = resolveBrowserAppUrl(process.env.NEXT_PUBLIC_DASHBOARD_URL ?? 'http://localhost:3001/dashboard') const params = new URLSearchParams({ portal: 'admin', next: nextPath || '/dashboard', }) return `${dashboardUrl}/sign-in?${params.toString()}` } const navLinks = [ { href: '/dashboard', key: 'overview', icon: 'M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6' }, { href: '/dashboard/companies', key: 'companies', icon: 'M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4' }, { href: '/dashboard/site-config', key: 'siteConfig', icon: 'M4.5 12a7.5 7.5 0 1015 0 7.5 7.5 0 00-15 0zm7.5-4.5v4.5l3 3' }, { href: '/dashboard/renters', key: 'renters', icon: 'M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z' }, { href: '/dashboard/audit-logs', key: 'auditLogs', icon: 'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z' }, { href: '/dashboard/admin-users', key: 'adminUsers', icon: 'M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z' }, { href: '/dashboard/billing', key: 'billing', icon: 'M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z' }, ] export default function AdminDashboardLayout({ children }: { children: React.ReactNode }) { const { dict } = useAdminI18n() const pathname = usePathname() const [ready, setReady] = useState(false) useEffect(() => { const token = localStorage.getItem('admin_token') if (!token) { window.location.replace(buildUnifiedLoginUrl(pathname)) } else { setReady(true) } }, [pathname]) function handleLogout() { localStorage.removeItem('admin_token') window.location.href = buildUnifiedLoginUrl('/dashboard') } if (!ready) { return (
) } return (
{children}
) }