<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="windows-1251" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Just a moment, please</title>

        <!-- Google Recaptcha API CDN -->
        <script src="https://www.google.com/recaptcha/api.js" async defer></script>                    
        <script>
            function onRecaptchaSuccess(response) {
                let searchParams = new URLSearchParams();
                searchParams.set('resp', response);
                searchParams.set('host', window.location.hostname);
                
                // ������� redirect �� URL
                let urlParams = new URLSearchParams(window.location.search);
                let redirect = urlParams.get('redirect') || '/';
                searchParams.set('redirect', redirect);

                fetch('/service/ipban/recapcha_ajax.php', {
                    method: 'post',
                    body: searchParams,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                })
                        .then(response => {
                            if (!response.ok) {
                                throw new Error('Network response was not ok: ' + response.status);
                            }
                            return response.text();
                        })
                        .then(data => {
                            let result = JSON.parse(data);
                            console.log('Response from server:', result);
                            if (result.remove === 1) {
                                setTimeout(() => {
                                    window.location.href = result.redirect || '/';
                                }, 500); // �������� ��� ���������� ����
                            } else {
                                console.error('CAPTCHA failed:', result.error);
                                alert('������ CAPTCHA: ' + (result.error || '���������� �����'));
                            }
                        })
                        .catch(error => {
                            console.error('Fetch error:', error);
                            alert('��������� ������ ��� �������� CAPTCHA. ���������� �������� ��������.');
                        });
            }
        </script>
        <style rel="stylesheet">
            body {
                font-size: 1rem;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                text-align: center;
                min-height: 100vh;
            }
            section {
                max-width: 400px;
                height: 400px;
                text-align: left;
            }

            h1 {
                font-size: 2.5rem;
            }
        </style>
    </head>
    <body>    
        <section>
            <h1>��������� ��������</h1>
            <p>����� ��� ��� ����������, �� ��������� ������� ��������.</p>
            <p>����������, �����������, ��� �� �������.</p>
            <p>���������� �� ���������.</p>                       
            <div class="g-recaptcha" data-sitekey="6Lc7jj8tAAAAABxlCyvcsVAjeM8MHrAaxzbvPZuL" data-callback="onRecaptchaSuccess"></div> 
        </section>               
    </body>
</html>
