<script src="https://accounts.google.com/gsi/client" async defer></script>
<script>
window.onload = function () {
    const GOOGLE_CLIENT_ID = '713764708426-mnfepjktss8vdi8lr7cfmko3bj3hmv6q.apps.googleusercontent.com';
    
    if (GOOGLE_CLIENT_ID) {
        google.accounts.id.initialize({
            client_id: GOOGLE_CLIENT_ID,
            callback: handleCredentialResponse
        });
        
        // Renderuj przycisk
        const googleButton = document.querySelector('.btn-google-auth');
        if (googleButton) {
            googleButton.onclick = function() {
                google.accounts.id.prompt();
            };
        }
    }
};

function handleCredentialResponse(response) {
    // Dekoduj JWT token
    const responsePayload = decodeJwtResponse(response.credential);
    
    // Wyślij do WordPress
    const formData = new FormData();
    formData.append('action', 'planpin_google_auth');
    formData.append('email', responsePayload.email);
    formData.append('name', responsePayload.name);
    formData.append('google_id', responsePayload.sub);
    formData.append('nonce', 'fb55c1979e');
    
    fetch('https://planpin.pl/wp-admin/admin-ajax.php', {
        method: 'POST',
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            window.location.href = data.redirect || 'https://planpin.pl/dashboard/';
        } else {
            alert(data.message || 'Błąd podczas logowania');
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('Błąd połączenia z serwerem');
    });
}

function decodeJwtResponse(token) {
    const base64Url = token.split('.')[1];
    const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
    const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));
    return JSON.parse(jsonPayload);
}
</script><?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://planpin.pl/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://planpin.pl/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://planpin.pl/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
