'use client'; import { useEffect, useMemo } from 'react'; import { useTranslations } from 'next-intl'; import { useAuth } from '@/lib/context/auth-context'; import { usePathname, useRouter } from '@/i18n/navigation'; import { useSubscription } from '@/lib/context/subscription-context'; import { AppShell } from '@/components/shell/app-shell'; import { buildAppNav } from '@/components/shell/nav-config'; import { PageSpinner } from '@/components/ui/states'; export default function DashboardLayout({ children }: { children: React.ReactNode }) { const { user, logout, loading, isAuthenticated } = useAuth(); const { hasFeature, subscription } = useSubscription(); const pathname = usePathname(); const router = useRouter(); const t = useTranslations('dashboard'); const tShell = useTranslations('shell'); useEffect(() => { if (!loading && !isAuthenticated) { router.replace(`/login?redirect=${encodeURIComponent(pathname)}`); } }, [loading, isAuthenticated, router, pathname]); const groups = useMemo( () => buildAppNav({ t, tShell, role: user?.role }), [t, tShell, user?.role] ); if (loading) { return (