import { useState, useEffect } from 'react'; import { MessageCircle, X, Send, MapPin, Search, Sparkles, Star, Clock, DollarSign } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; interface Message { id: string; type: 'user' | 'ai'; content: string; timestamp: Date; suggestions?: string[]; results?: SearchResult[]; } interface SearchResult { id: string; title: string; type: 'restaurant' | 'hotel' | 'attraction' | 'event' | 'shop'; description: string; rating: number; price: string; distance: string; image: string; location: string; available: boolean; } const QUICK_ACTIONS = [ { id: 'restaurants', label: '🍽️ Find Restaurants', query: 'Find the best restaurants near me' }, { id: 'hotels', label: '🏨 Hotels & Stays', query: 'Show me hotels and accommodations nearby' }, { id: 'attractions', label: '🎭 Attractions', query: 'What are the top attractions to visit here?' }, { id: 'events', label: '🎪 Events Today', query: 'What events are happening today in my area?' }, { id: 'shopping', label: '🛍️ Shopping', query: 'Find shopping centers and stores near me' }, { id: 'deals', label: '💰 Best Deals', query: 'Show me the best deals and offers available' } ]; const SAMPLE_RESULTS: SearchResult[] = [ { id: '1', title: 'La Terrazza Restaurant', type: 'restaurant', description: 'Authentic Italian cuisine with ocean views', rating: 4.8, price: '$$$', distance: '0.3 km', image: 'https://images.unsplash.com/photo-1414235077428-338989a2e8c0?w=300&h=200&fit=crop', location: 'Downtown', available: true }, { id: '2', title: 'Ocean View Hotel', type: 'hotel', description: 'Luxury beachfront hotel with spa services', rating: 4.6, price: '$150/night', distance: '0.8 km', image: 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=300&h=200&fit=crop', location: 'Beachfront', available: true }, { id: '3', title: 'Art Museum Moderna', type: 'attraction', description: 'Contemporary art collection and exhibitions', rating: 4.4, price: '$12', distance: '1.2 km', image: 'https://images.unsplash.com/photo-1554907984-15263bfd63bd?w=300&h=200&fit=crop', location: 'Cultural District', available: true } ]; export function AIFloatingAssistant() { const [isOpen, setIsOpen] = useState(false); const [messages, setMessages] = useState([]); const [inputValue, setInputValue] = useState(''); const [isTyping, setIsTyping] = useState(false); const [userLocation, setUserLocation] = useState(''); useEffect(() => { // Get user location if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( (position) => { const { latitude, longitude } = position.coords; // In a real app, you'd reverse geocode these coordinates setUserLocation(`${latitude.toFixed(4)}, ${longitude.toFixed(4)}`); }, (error) => { console.error('Error getting location:', error); setUserLocation('Location unavailable'); } ); } }, []); useEffect(() => { if (isOpen && messages.length === 0) { // Welcome message const welcomeMessage: Message = { id: '1', type: 'ai', content: `¡Hola! 👋 Soy tu asistente de IA de Karibeo. Estoy aquí para ayudarte a encontrar los mejores lugares, ofertas y experiencias según tu ubicación. ¿En qué puedo ayudarte hoy?`, timestamp: new Date(), suggestions: [ 'Encuentra restaurantes cerca', 'Hoteles disponibles', 'Mejores ofertas del día', 'Eventos y actividades' ] }; setMessages([welcomeMessage]); } }, [isOpen, messages.length]); const handleSendMessage = async (query: string) => { if (!query.trim()) return; const userMessage: Message = { id: Date.now().toString(), type: 'user', content: query, timestamp: new Date() }; setMessages(prev => [...prev, userMessage]); setInputValue(''); setIsTyping(true); // Simulate AI processing setTimeout(() => { const aiResponse = generateAIResponse(query); setMessages(prev => [...prev, aiResponse]); setIsTyping(false); }, 1500); }; const generateAIResponse = (query: string): Message => { const lowerQuery = query.toLowerCase(); let response = ''; let results: SearchResult[] = []; let suggestions: string[] = []; if (lowerQuery.includes('restaurant') || lowerQuery.includes('comida') || lowerQuery.includes('comer')) { response = '🍽️ He encontrado algunos restaurantes excelentes cerca de ti:'; results = SAMPLE_RESULTS.filter(r => r.type === 'restaurant'); suggestions = ['Reservar mesa', 'Ver menú', 'Más restaurantes', 'Ofertas especiales']; } else if (lowerQuery.includes('hotel') || lowerQuery.includes('hospedaje') || lowerQuery.includes('alojamiento')) { response = '🏨 Aquí tienes las mejores opciones de hospedaje:'; results = SAMPLE_RESULTS.filter(r => r.type === 'hotel'); suggestions = ['Verificar disponibilidad', 'Comparar precios', 'Ver fotos', 'Reservar ahora']; } else if (lowerQuery.includes('atracciones') || lowerQuery.includes('lugares') || lowerQuery.includes('visitar')) { response = '🎭 Estas son las atracciones más populares:'; results = SAMPLE_RESULTS.filter(r => r.type === 'attraction'); suggestions = ['Comprar entradas', 'Ver horarios', 'Más atracciones', 'Tours guiados']; } else if (lowerQuery.includes('ofertas') || lowerQuery.includes('descuentos') || lowerQuery.includes('deals')) { response = '💰 ¡Encontré estas ofertas especiales para ti!'; results = SAMPLE_RESULTS.map(r => ({ ...r, price: `${r.price} - 20% OFF` })); suggestions = ['Ver más ofertas', 'Códigos de descuento', 'Ofertas flash', 'Membresías']; } else { response = `He buscando información sobre "${query}" en tu área. Aquí tienes algunas opciones que podrían interesarte:`; results = SAMPLE_RESULTS.slice(0, 2); suggestions = ['Búsqueda específica', 'Filtrar por precio', 'Ordenar por distancia', 'Ver mapa']; } return { id: Date.now().toString(), type: 'ai', content: response, timestamp: new Date(), results, suggestions }; }; const handleQuickAction = (action: typeof QUICK_ACTIONS[0]) => { handleSendMessage(action.query); }; const renderSearchResults = (results: SearchResult[]) => { return (
{results.map((result) => (
{result.title}

{result.title}

{result.available ? 'Disponible' : 'Ocupado'}

{result.description}

{result.rating}
{result.distance}
{result.price}
))}
); }; return ( <> {/* Floating Button */}
{/* Chat Modal */} {isOpen && (
{/* Header */}
AI

Asistente Karibeo

{userLocation ? `📍 ${userLocation}` : '🤖 Conectado'}

{/* Quick Actions */} {messages.length <= 1 && (

Acciones rápidas:

{QUICK_ACTIONS.slice(0, 4).map((action) => ( ))}
)} {/* Messages */}
{messages.map((message) => (

{message.content}

{message.results && renderSearchResults(message.results)} {message.suggestions && (
{message.suggestions.map((suggestion, index) => ( ))}
)}
))} {isTyping && (
)}
{/* Input */}
setInputValue(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSendMessage(inputValue)} placeholder="Escribe tu pregunta..." className="flex-1" disabled={isTyping} />
)} ); }