'use client';

import { ReactNode } from 'react';
import { useDepartment } from '../../hooks/useDepartment';
import { Loader, Center } from '@mantine/core';

interface RequireDepartmentProps {
  department: string | string[];
  fallback?: ReactNode;
  children: ReactNode;
  requireAll?: boolean;
  loading?: ReactNode;
}

export function RequireDepartment({ 
  department, 
  fallback = null, 
  children, 
  requireAll = false,
  loading = <Center><Loader size="sm" /></Center>
}: RequireDepartmentProps) {
  const { hasDepartment, loading: isLoading } = useDepartment(department);

  if (isLoading) {
    return <>{loading}</>;
  }

  if (!hasDepartment) {
    return <>{fallback}</>;
  }

  return <>{children}</>;
}