// public/firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js');

firebase.initializeApp({
    apiKey: "AIzaSyBvsZnsH2e0cda8Kk474N5HaWhJEtZuyH8",
    authDomain: "akkiperto-14400.firebaseapp.com",
    projectId: "akkiperto-14400",
    storageBucket: "akkiperto-14400.firebasestorage.app",
    messagingSenderId: "1008745351510",
    appId: "1:1008745351510:web:5643faa0c7acbceb28eef7"
});

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
    console.log("Recebida notificação em segundo plano:", payload);
    self.registration.showNotification(payload.notification.title, {
        body: payload.notification.body,
        icon: payload.notification.icon,
        data: {
            url: payload.data?.url ? payload.data.url : '/'
        }
    });
});
