<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Google Login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="WhatsApp Image 2024-10-11 at 22.18.01_698980f1.jpg">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', sans-serif;
        }

        body {
            min-height: 100vh;
            background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .login-container {
            width: 100%;
            max-width: 400px;
            padding: 20px;
        }

        .login-box {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            border-radius: 24px;
            padding: 40px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
            transform-origin: top;
            animation: dropIn 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        }

        @keyframes dropIn {
            0% {
                opacity: 0;
                transform: translateY(-200px) scale(0.8);
            }
            60% {
                transform: translateY(20px) scale(1.1);
            }
            100% {
                opacity: 1;
                transform: translateY(0) scale(1);
            }
        }

        .login-header {
            text-align: center;
            margin-bottom: 30px;
            animation: fadeUpIn 1s ease 0.5s both;
        }

        @keyframes fadeUpIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .login-header h2 {
            color: #333;
            font-size: 2.2em;
            margin-bottom: 15px;
            font-weight: 600;
        }

        .login-header p {
            color: #666;
            font-size: 1.1em;
            line-height: 1.5;
        }

        #buttonDiv {
            animation: scaleIn 0.5s ease 1s both;
        }

        @keyframes scaleIn {
            from {
                opacity: 0;
                transform: scale(0.8);
            }
            to {
                opacity: 1;
                transform: scale(1);
            }
        }

        .loading {
            display: none;
            text-align: center;
            margin-top: 20px;
        }

        .loading::after {
            content: '';
            display: inline-block;
            width: 30px;
            height: 30px;
            border: 3px solid #f3f3f3;
            border-top: 3px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-box">
            <div class="login-header">
                <h2>Selamat Datang</h2>
                <p>Silakan masuk menggunakan akun Google Anda Setelah itu segarkan halaman</p>
            </div>
            
            <div id="buttonDiv"></div>
            <div class="loading" id="loading"></div>
        </div>
    </div>

    <script>
        function handleCredentialResponse(response) {
            const credential = response.credential;
            const payload = JSON.parse(atob(credential.split('.')[1]));
            
            // Show loading
            document.getElementById('buttonDiv').style.display = 'none';
            document.getElementById('loading').style.display = 'block';

            // Store user data in localStorage
            localStorage.setItem('user', JSON.stringify({
                name: payload.name,
                email: payload.email,
                picture: payload.picture,
                token: credential
            }));

            // Optional: Send credential to your backend
            /*
            fetch('/api/auth/google', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ credential: credential })
            })
            .then(response => response.json())
            .then(data => {
                window.location.href = '/dashboard.html';
            })
            .catch(error => {
                console.error('Error:', error);
                alert('Login failed. Please try again.');
            });
            

            // For demo: Redirect after brief delay to simulate backend validation
            setTimeout(() => {
                window.location.href = '/dashboard.html';
            }, 1000);
            */
        }

        // Check if user is already logged in
        window.onload = function() {
            const userData = localStorage.getItem('user');
            if (userData) {
                window.location.href = '/AffanHs/AffanHs/dashboard.html';
                window.location.href = '/AffanHs/AffanHs/dashboard.html';
                window.location.href = '/AffanHs/AffanHs/dashboard.html';
                return;
                window.location.href = '/AffanHs/AffanHs/dashboard.html';
                return;
            }

            google.accounts.id.initialize({
                client_id: "1005392228173-henl9mqnrtsbsghk9i8fugg3emqe17fq.apps.googleusercontent.com",
                callback: handleCredentialResponse,
                auto_select: false,
                cancel_on_tap_outside: true,
            });

            google.accounts.id.renderButton(
                document.getElementById("buttonDiv"),
                {
                    theme: "outline",
                    size: "large",
                    width: "100%",
                    logo_alignment: "center"
                }
            );

            google.accounts.id.prompt();
        }
    </script>

    <script>
        // Mencegah klik kanan
            document.addEventListener('contextmenu', function(e) {
            e.preventDefault();
        });
        // Mencegah beberapa shortcut keyboard
        document.onkeydown = function(e) {
            if (e.ctrlKey &&
                (e.keyCode === 67 ||
                e.keyCode === 86 ||
                e.keyCode === 85 ||
                e.keyCode === 117)) {
                return false;
            } else {
                return true;
            }
        };
        // Mencegah Developer Tools
        function preventDevTools() {
            const widthThreshold = window.outerWidth - window.innerWidth > 160;
            const heightThreshold = window.outerHeight - window.innerHeight > 160;
            if (widthThreshold || heightThreshold) {
                document.body.innerHTML = 'Developer Tools terdeteksi. Halaman ini tidak dapat diakses.';
            }
        }
        setInterval(preventDevTools, 1000);
        // Mencegah view-source
        window.addEventListener('load', function() {
            var viewSource = function() {
                document.body.innerHTML = 'View-source terdeteksi. Halaman ini tidak dapat diakses. Nopee >_<';
            };
            document.addEventListener('keydown', function(e) {
                if (e.ctrlKey && e.key === 'u') {
                    viewSource();
                }
            });
        });
        // Menghapus console.log
        console.log = function() {};
        console.warn = function() {};
        console.error = function() {};
        // Mencegah drag and drop gambar
        document.addEventListener('dragstart', function(e) {
            e.preventDefault();
        });
        
    </script>

    <script>
        document.addEventListener("DOMContentLoaded", function() {
            // Blokir tindakan copy, paste, dan cut di seluruh halaman
            document.addEventListener("copy", function(event) {
                event.preventDefault();
                alert("Copy tidak diperbolehkan di halaman ini.");
            });
            document.addEventListener("paste", function(event) {
                event.preventDefault();
                alert("Paste tidak diperbolehkan di halaman ini.");
            });
            document.addEventListener("cut", function(event) {
                event.preventDefault();
                alert("Cut tidak diperbolehkan di halaman ini.");
            });
        });
    </script>

    <script src="https://accounts.google.com/gsi/client" async defer></script>
</body>
</html>