<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Microsoft Authentication</title>
</head>
<body style="font-family: system-ui, -apple-system, sans-serif; display:flex; align-items:center; justify-content:center; height:100vh; margin:0; background:#f3f4f6;">
    <div style="text-align:center; max-width:420px; padding:24px;">
        @if($success)
            <p style="color:#059669;font-weight:600;">Connected to Microsoft{{ isset($accountEmail) ? " as {$accountEmail}" : '' }}.</p>
            <p style="color:#6b7280;font-size:14px;">You can close this window.</p>
        @else
            <p style="color:#dc2626;font-weight:600;">Authentication failed</p>
            <p style="color:#6b7280;font-size:14px;">{{ $message }}</p>
        @endif
    </div>
    <script>
        (function () {
            var payload = @json([
                'type'         => 'microsoft-oauth-result',
                'success'      => $success,
                'message'      => $message ?? null,
                'refreshToken' => $refreshToken ?? null,
                'accessToken'  => $accessToken ?? null,
                'expiresAt'    => $expiresAt ?? null,
                'accountEmail' => $accountEmail ?? null,
            ]);

            if (window.opener) {
                window.opener.postMessage(payload, window.location.origin);
            }

            setTimeout(function () { window.close(); }, payload.success ? 1200 : 5000);
        })();
    </script>
</body>
</html>
