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

//Using singleton breaks instantiating messaging()
// App firebase = FirebaseWeb.instance.app;


const firebaseConfig = {
    apiKey: "AIzaSyA0HZjKpRuPOi1SC3f_EZTvlS3mcj9UVo0",
    authDomain: "didvan-9b7da.firebaseapp.com",
    projectId: "didvan-9b7da",
    storageBucket: "didvan-9b7da.appspot.com",
    messagingSenderId: "935017686266",
    appId: "1:935017686266:web:a93f7a19bed23c51d2d543",
    measurementId: "G-80B4H9E8Y0"
};


console.log(firebase, 'kireomidyekamshaghshode');
const init = firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function (payload) {
    const promiseChain = clients
        .matchAll({
            type: "window",
            includeUncontrolled: true
        })
        .then(windowClients => {
            for (let i = 0; i < windowClients.length; i++) {
                const windowClient = windowClients[i];
                windowClient.postMessage(payload);
            }
        })
        .then(() => {
            return registration.showNotification("New Message");
        });
    return promiseChain;
});
self.addEventListener('notificationclick', function (event) {
    console.log('notification received: ', event)
});