"use client";

import { useAuthGuard } from '@/hooks/useAuthGuard';
import AuthenticatedLayout from '@/layouts/AuthenticatedLayout';
import { RootProvider } from '@/contexts/RootProvider';

/**
 * Protected Layout
 *
 * Purpose:
 * - Apply authentication guard to all protected pages
 * - Apply common layout (sidebar, header) to all protected pages
 * - Provide global context (RootProvider)
 * - Prevent browser back button cache issues
 * - Centralized protection for all routes under (protected)
 *
 * Protected Routes:
 * - /dashboard
 * - /items/* (품목관리)
 * - /master-data/* (기준정보관리)
 * - /production/* (생산관리)
 * - All other authenticated pages
 */
export default function ProtectedLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  // 🔒 모든 하위 페이지에 인증 보호 적용
  useAuthGuard();

  // 🎨 모든 하위 페이지에 공통 레이아웃 및 Context 적용
  return (
    <RootProvider>
      <AuthenticatedLayout>{children}</AuthenticatedLayout>
    </RootProvider>
  );
}