'use client';

import { useAppSelector } from "@/lib/redux/hooks";
import { selectBoxItems } from "@/lib/redux/slices/boxSlice";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";

export function RedirectIfEmptyBox() {
  const router = useRouter();
  const items = useAppSelector(selectBoxItems);
  const [isMounted, setIsMounted] = useState(false);
  
  useEffect(() => {
    setIsMounted(true);
  }, []);
  
  useEffect(() => {
    if (isMounted && items.length === 0) {
      router.replace('/build-box');
    }
  }, [items, router, isMounted]);
  
  return null;
} 