import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
import { createRouteGuard } from '@/lib/auth/createRouteGuard';

interface DashboardLayoutProps {
  children: React.ReactNode;
}

/**
 * Dashboard Layout
 *
 * Provides authentication protection for all dashboard routes.
 * Uses RouteGuard to enforce access control server-side.
 */
export default async function DashboardLayout({ children }: DashboardLayoutProps) {
  const headerStore = await headers();
  const pathname = headerStore.get('x-pathname') || '/';
  
  const guard = createRouteGuard();
  const result = await guard.enforce({ pathname });
  if (result.type === 'redirect') {
    redirect(result.to);
  }
  
  return (
    <div className="min-h-screen bg-deep-graphite">
      {children}
    </div>
  );
}
