'use client';

import { useAuth } from '@/services/hooks/useAuth';

interface RequirePermissionProps {
  children: React.ReactNode;
  permissions: string | string[];
}

const RequirePermission = ({
  children,
  permissions,
}: RequirePermissionProps) => {
  const { permissionCheck } = useAuth();

  const isPermitted =
    typeof permissions === 'string'
      ? permissionCheck(permissions)
      : permissions.some((permission) => permissionCheck(permission));

  if (!isPermitted) {
    return null;
  }

  return <>{children}</>;
};

export default RequirePermission;
