"use client";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useState, type ReactNode } from "react";

/**
 * The public check-in lane is NOT wrapped by the buyer app's provider, so it
 * needs its own QueryClient — the status poller (Task 5) and the submit
 * mutation (Task 4) both depend on one. Slow-polling defaults: a long
 * staleTime, no window-focus refetch (mobile, flaky cellular), no auto-retry
 * (the idempotency key makes a manual retry safe and explicit).
 */
export function CheckinQueryProvider({ children }: { children: ReactNode }) {
  const [client] = useState(
    () =>
      new QueryClient({
        defaultOptions: {
          queries: {
            staleTime: 30_000,
            refetchOnWindowFocus: false,
            retry: false,
          },
        },
      }),
  );

  return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
}
