"use client";

import { useEffect } from "react";

export function ServiceWorkerRegistration() {
  useEffect(() => {
    if (
      typeof window === "undefined" ||
      !("serviceWorker" in navigator) ||
      process.env.NODE_ENV === "development"
    ) {
      return;
    }

    navigator.serviceWorker
      .register("/sw.js")
      .then((registration) => {
        // Check for updates every 60 minutes
        setInterval(() => {
          registration.update().catch(() => {
            // Silent fail on update check
          });
        }, 60 * 60 * 1000);
      })
      .catch(() => {
        // Service worker registration failed — non-critical
      });
  }, []);

  return null;
}
