import { useState } from "react"; import { Alert, Platform, Text, TouchableOpacity } from "react-native"; import { useAuth } from "@/contexts/AuthContext"; import { LogoutConfirmModal } from "./LogoutConfirmModal"; interface LogoutButtonProps { className?: string; variant?: "default" | "destructive" | "ghost"; } export function LogoutButton({ className = "" }: LogoutButtonProps) { const { logout } = useAuth(); const [showConfirmModal, setShowConfirmModal] = useState(false); const handleLogoutPress = () => { if (Platform.OS === "web") { setShowConfirmModal(true); } else { // Mobile: use Alert.alert Alert.alert("Sign Out", "Are you sure you want to sign out?", [ { text: "Cancel", style: "cancel", }, { text: "Sign Out", style: "destructive", onPress: performLogout, }, ]); } }; const performLogout = async () => { try { await logout(); } catch (error) { const message = error instanceof Error ? error.message : String(error); console.error("Logout error", message); if (__DEV__) { const stack = error instanceof Error ? error.stack : undefined; console.debug("[LogoutButton] logout failed", { message, stack }); } if (Platform.OS === "web") { window.alert("Failed to sign out. Please try again."); } else { Alert.alert("Error", "Failed to sign out. Please try again."); } } }; const handleConfirmLogout = () => { setShowConfirmModal(false); performLogout(); }; const handleCancelLogout = () => { setShowConfirmModal(false); }; return ( <> Sign Out ); } export default LogoutButton;