// Import the scripts you need
importScripts('https://www.gstatic.com/firebasejs/10.5.2/firebase-app-compat.js')
importScripts('https://www.gstatic.com/firebasejs/10.5.2/firebase-messaging-compat.js')

// Initialize Firebase in the service worker
firebase.initializeApp({
  apiKey: "AIzaSyCy-vNoN_kBjEkSMjqQRErfV0pMlnRwl6c",
  authDomain: "pwa-project-a2db2.firebaseapp.com",
  projectId: "pwa-project-a2db2",
  storageBucket: "pwa-project-a2db2.firebasestorage.app",
  messagingSenderId: "525701580315",
  appId: "1:525701580315:web:8aca5ff8ed4a3ed3bc1abe",
  measurementId: "G-296EK3K9TX"
});

// Retrieve an instance of Firebase Messaging so that it can handle background messages.
const messaging = firebase.messaging();

// Keep a fetch handler so Chromium marks the app installable.
self.addEventListener('fetch', () => {});

messaging.onBackgroundMessage((payload) => {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
  // Customize notification here
  const notificationTitle = payload.notification.title;
  const notificationOptions = {
    body: payload.notification.body,
    icon: payload.notification.icon
  };

  self.registration.showNotification(notificationTitle, notificationOptions);
});