import { register } from 'register-service-worker'

register(process.env.SERVICE_WORKER_FILE, {
  ready () {},
  registered (reg) {
    // Check for updates every 5 minutes
    setInterval(() => { reg.update() }, 5 * 60 * 1000)
  },
  cached () {},
  updatefound () {},
  updated (reg) {
    // New service worker available — activate it silently (no reload)
    if (reg && reg.waiting) {
      reg.waiting.postMessage({ type: 'SKIP_WAITING' })
    }
  },
  offline () {},
  error () {}
})
