// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here. Other Firebase libraries
// are not available in the service worker.
// Replace 10.13.2 with latest version of the Firebase JS SDK.
importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js');

// Initialize the Firebase app in the service worker by passing in
// your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({
  apiKey: "AIzaSyC14hS0_idUIRS9JEigObmT-_CGl3zb8Fo",
  authDomain: "thirukalyanam-c8e1c.firebaseapp.com",
  projectId: "thirukalyanam-c8e1c",
  storageBucket: "thirukalyanam-c8e1c.firebasestorage.app",
  messagingSenderId: "433615056618",
  appId: "1:433615056618:web:309a920f408ba826907193",
  measurementId: "G-1L93F6DS7K"
});

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



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.image || "/favicon.ico",
     data: {
      url: "/notification" // 👈 set target URL
    }
  };

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