/* eslint-disable sonarjs/function-return-type */
'use client';

import { useIsBanned } from '@/hooks/api/customers';
import { redirect, RedirectType } from 'next/navigation';
import { type PropsWithChildren, useEffect } from 'react';

export function CheckBanned({ children }: Readonly<PropsWithChildren>) {
  const isBanned = useIsBanned();

  useEffect(() => {
    if (isBanned) {
      redirect('/banned', RedirectType.replace);
    }
  }, [isBanned]);

  if (isBanned) return null;

  return children;
}
