import React, { useState } from 'react'; import { Calendar, Link, CheckCircle2, AlertCircle, Loader2 } from 'lucide-react'; interface GoogleConnectButtonProps { ownerId: string; // Ex: 'admin' ou o ID do dentista isConnected: boolean; onStatusChange?: () => void; } export const GoogleConnectButton: React.FC = ({ ownerId, isConnected, onStatusChange }) => { const [isLoading, setIsLoading] = useState(false); const handleConnect = async () => { setIsLoading(true); try { const response = await fetch(`http://localhost:3005/api/auth/google/url?dentistId=${ownerId}`); const { url } = await response.json(); // Abrir em popup para manter o contexto const width = 600; const height = 700; const left = window.screen.width / 2 - width / 2; const top = window.screen.height / 2 - height / 2; const popup = window.open( url, 'google-auth', `width=${width},height=${height},left=${left},top=${top}` ); // Verificar se o popup fechou a cada 1s const checkPopup = setInterval(() => { if (!popup || popup.closed) { clearInterval(checkPopup); setIsLoading(false); if (onStatusChange) onStatusChange(); } }, 1000); } catch (error) { console.error('Erro ao conectar Google Agenda:', error); setIsLoading(false); } }; const handleDisconnect = async () => { if (!confirm('Deseja realmente desconectar esta agenda?')) return; setIsLoading(true); try { await fetch(`http://localhost:3005/api/auth/google/${ownerId}`, { method: 'DELETE' }); if (onStatusChange) onStatusChange(); } catch (error) { console.error('Erro ao desconectar:', error); } finally { setIsLoading(false); } }; if (isConnected) { return (

Google Agenda Conectada

Sincronização Ativa

); } return ( ); };