import { useState, useEffect } from 'react'; import { useLocation } from 'react-router-dom'; import { MessageCircle, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { useGlobalChat } from '@/hooks/useGlobalChat'; import { useAppContext } from '@/hooks/useAppContext'; import { useIsMobile } from '@/hooks/useIsMobile'; import { cn } from '@/lib/utils'; export function FloatingChatButton() { const { isOpen, setIsOpen, hasUnread } = useGlobalChat(); const { config } = useAppContext(); const location = useLocation(); const isMobile = useIsMobile(); const [isHovered, setIsHovered] = useState(false); const [isHiddenTemporarily, setIsHiddenTemporarily] = useState(false); // Reset hidden state when navigating to a different page useEffect(() => { setIsHiddenTemporarily(false); }, [location.pathname]); // Don't render if disabled in settings if (config.globalChatEnabled === false) { return null; } // Don't render on settings pages if (location.pathname.startsWith('/settings')) { return null; } // On mobile, only show on home screen (/ or /giftcard) const isHomePage = location.pathname === '/' || location.pathname === '/giftcard'; if (isMobile && !isHomePage) { return null; } // Don't render if temporarily hidden if (isHiddenTemporarily) { return null; } const handleClose = (e: React.MouseEvent) => { e.stopPropagation(); setIsHiddenTemporarily(true); }; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {/* Main chat button */} {/* Close button - appears on hover, rendered last to be on top */}
); }