"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";

/**
 * Polls the order status page for updates while payment is still pending
 * (FR-062) by asking the Server Component to re-fetch every few seconds.
 * Unmounts naturally once the parent re-renders with a non-pending status.
 */
export function StatusPoller({ intervalMs = 4000 }: { intervalMs?: number }) {
  const router = useRouter();

  useEffect(() => {
    const id = setInterval(() => router.refresh(), intervalMs);
    return () => clearInterval(id);
  }, [router, intervalMs]);

  return null;
}
