import type { ReactNode } from 'react';
import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
import { ProfileLayoutShellTemplate } from '@/templates/ProfileLayoutShellTemplate';
import { createRouteGuard } from '@/lib/auth/createRouteGuard';

interface ProfileLayoutProps {
  children: ReactNode;
}

export default async function ProfileLayout({ children }: ProfileLayoutProps) {
  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 <ProfileLayoutShellTemplate viewData={{}}>{children}</ProfileLayoutShellTemplate>;
}
