if ('serviceWorker' in navigator) {
    // Absolute URL kullanarak service worker kaydı yap
    navigator.serviceWorker.register('/admin/service-worker.js', {scope: '/admin/'})
        .then(function(registration) {
            console.log('Service Worker registered with scope:', registration.scope);
        })
        .catch(function(error) {
            console.error('Service Worker registration failed:', error);
            // Hata sadece loglanır, kullanıcı deneyimini etkilemez
        });
}

window.addEventListener('beforeinstallprompt', (event) => {
    event.preventDefault(); 
    const installButton = document.getElementById('installButton');
    installButton.style.display = 'block';

    installButton.addEventListener('click', () => {
        event.prompt();
        event.userChoice.then((choiceResult) => {
            if (choiceResult.outcome === 'accepted') {
                console.log('PWA kurulumu kabul edildi');
                installButton.style.display = 'none';
            } else {
                console.log('PWA kurulumu iptal edildi');
            }
        });
    });
});
