'use client';

import { usePageAccess } from '@/src/components/admin/hoc/withPageAccess';
import { ReactNode } from 'react';

interface PageProtectionProps {
  pageSlug: string;
  children: ReactNode;
}

export default function PageProtection({ pageSlug, children }: PageProtectionProps) {
  const { hasAccess, isLoading } = usePageAccess(pageSlug);

  if (isLoading) {
    return (
      <div className="flex items-center justify-center min-h-screen">
        <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
      </div>
    );
  }

  if (!hasAccess) return null;

  return <>{children}</>;
}
