importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-messaging-compat.js');

firebase.initializeApp({
  apiKey: 'YOUR_FIREBASE_WEB_API_KEY',
  appId: 'YOUR_FIREBASE_WEB_APP_ID',
  messagingSenderId: 'YOUR_FIREBASE_PROJECT_NUMBER',
  projectId: 'YOUR_FIREBASE_PROJECT_ID',
  authDomain: 'YOUR_FIREBASE_PROJECT_ID.firebaseapp.com',
  storageBucket: 'YOUR_FIREBASE_PROJECT_ID.firebasestorage.app',
});

const messaging = firebase.messaging();

// Handle background messages
messaging.onBackgroundMessage((payload) => {
  console.log('[firebase-messaging-sw.js] Received background message:', payload);

  const notificationTitle = payload.notification?.title || 'New Message';
  const notificationOptions = {
    body: payload.notification?.body || '',
    icon: '/icons/Icon-192.png',
    badge: '/icons/Icon-192.png',
  };

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