"use client";

import { SWRConfig } from "swr";

const swrConfig = {
  fetcher: async (url: string) => {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json();
  },
  revalidateOnFocus: false,
  revalidateOnReconnect: true,
  dedupingInterval: 2000,
  onError: () => {},
  keepPreviousData: true,
  focusThrottleInterval: 5000,
  refreshInterval: 0,
  refreshWhenHidden: false,
  refreshWhenOffline: false,
  compare: (a: unknown, b: unknown) => a === b,
};

const SWRProvider = ({ children }: { children: React.ReactNode }) => {
  return <SWRConfig value={swrConfig}>{children}</SWRConfig>;
};

export { SWRProvider };
