'use client' import { useState, useEffect } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { MessageCircle, X } from 'lucide-react' import { Button } from '@/components/ui/button' interface FloatingWhatsAppProps { phoneNumber: string message?: string position?: 'bottom-right' | 'bottom-left' showTooltip?: boolean } export default function FloatingWhatsApp({ phoneNumber, message = "Hello! I'm interested in your products.", position = 'bottom-right', showTooltip = true }: FloatingWhatsAppProps) { const [isVisible, setIsVisible] = useState(false) const [showTooltipState, setShowTooltipState] = useState(false) useEffect(() => { // Show the button after 3 seconds const timer = setTimeout(() => { setIsVisible(true) // Show tooltip after button appears (if enabled) if (showTooltip) { setTimeout(() => { setShowTooltipState(true) }, 1000) // Hide tooltip after 5 seconds setTimeout(() => { setShowTooltipState(false) }, 6000) } }, 3000) return () => clearTimeout(timer) }, [showTooltip]) const handleWhatsAppClick = () => { const encodedMessage = encodeURIComponent(message) const whatsappUrl = `https://wa.me/${phoneNumber}?text=${encodedMessage}` window.open(whatsappUrl, '_blank') } const positionClasses = { 'bottom-right': 'bottom-6 right-6', 'bottom-left': 'bottom-6 left-6' } return ( {isVisible && (
{/* Tooltip */} {showTooltipState && (

👋 Need help? Chat with us on WhatsApp!

We typically reply within minutes

{/* Arrow */}
)}
{/* WhatsApp Button */}
)}
) }