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

// Your Firebase config again
firebase.initializeApp({
  apiKey: "AIza...",
  authDomain: "your-app.firebaseapp.com",
  projectId: "your-app",
  storageBucket: "your-app.appspot.com",
  messagingSenderId: "1234567890",
  appId: "1:1234567890:web:abcdef"
});

const messaging = firebase.messaging();

messaging.onBackgroundMessage(function(payload) {
  console.log('📩 Received background message: ', payload);
  const { title, body } = payload.notification;
  const notificationOptions = {
    body,
    icon: '/chat-icon.png' // Optional
  };

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