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

// Initialize Firebase in the service worker
firebase.initializeApp({
  apiKey: "AIzaSyBetjax8O5Bn5a9_zpkHaOJgqzyL2nNhIw",
  authDomain: "pwa1-7f93b.firebaseapp.com",
  projectId: "pwa1-7f93b",
  storageBucket: "pwa1-7f93b.firebasestorage.app",
  messagingSenderId: "750994716686",
  appId: "1:750994716686:web:c8b64ada3a2ae494dda45f",
  measurementId: "G-T5V6VELR14"
});

// 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);
});