if (!("Notification" in window)) {
    //alert("This browser does not support desktop notification");
}else if (Notification.permission === "granted") {
    //var notification = new Notification("Hi there!");
} else{
    Notification.requestPermission().then(function (permission) {
        if (permission === "granted") {
           // initFirebase();
        }
    });
} 


function initFirebase(){
    const firebaseConfig = {
        apiKey: "AIzaSyCppXJijGHXBj_NXYdjlQTvwzYs3dnJ9wM",
        authDomain: "gabon-pay.firebaseapp.com",
        projectId: "gabon-pay",
        storageBucket: "gabon-pay.appspot.com",
        messagingSenderId: "414000424685",
        appId: "1:414000424685:web:164ef02f244ec2b09b0ee4",
        measurementId: "G-HYL0644JW6",
    };

    firebase.initializeApp(firebaseConfig);
    const messaging = firebase.messaging();

    messaging.usePublicVapidKey("BElO0SXiBKsR4NO5UO9Uv9sca39ebhFR96nWa_ygbrTjNr5kgdEwJGo8VujHx-isd914R8oBOYY98o9mvwPcS4I");

    messaging.getToken().then((currentToken) => {
        alert(currentToken);
            if (currentToken) {
                var req = $.ajax({
                    url: "https://www.gabonpay.com/api/device",
                    type: "POST",
                    data: {push_token: currentToken, user_id: _auth, platform : 'web', app_version : '1.0.0', provider : 'FIREBASE'},
                    dataType: "html",
                });
                req.done(function (response, textStatus, jqXHR) {});
                req.fail(function (jqXHR, textStatus) {});
            } else {
                console.log("No Instance ID token available. Request permission to generate one.");
            }
    }).catch((err) => {
            console.log("An error occurred while retrieving token. ", err);
    });

    messaging.onMessage((payload) => {
        console.log('Message received. ', payload);
    });
}
