<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Completing Google Sign-In</title>
</head>
<body>
    <p>Completing Google sign-in...</p>

    <script>
        (() => {
            const nextUrl = @json($nextUrl);
            const targetOrigin = @json($targetOrigin ?? request()->getSchemeAndHttpHost());
            const errorMessage = @json($errorMessage ?? null);
            const messageType = errorMessage
                ? 'remotematch.google-auth.failed'
                : 'remotematch.google-auth.success';

            if (window.opener && !window.opener.closed) {
                window.opener.postMessage({
                    type: messageType,
                    nextUrl,
                    errorMessage,
                }, targetOrigin);

                window.close();
            }

            window.setTimeout(() => {
                window.location.replace(nextUrl);
            }, 500);
        })();
    </script>
</body>
</html>
