"use client"; import React, { useState, useEffect, useRef } from "react"; import { Button, Card, CardHeader, CardBody, CardFooter, Input, Avatar, ScrollShadow, Badge, } from "@heroui/react"; import { motion, AnimatePresence } from "framer-motion"; import { HeartFilledIcon } from "./icons"; import { fontCursive } from "@/config/fonts"; interface Message { role: "user" | "bot"; text: string; } const ConciergeBot = () => { const [isOpen, setIsOpen] = useState(false); const [input, setInput] = useState(""); const [messages, setMessages] = useState([ { role: "bot", text: "Namaste! I am your Wedding Concierge. How can I help you today?", }, ]); const [isTyping, setIsTyping] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, isTyping]); const handleSend = async () => { if (!input.trim()) return; const userMsg = input.trim(); setMessages((prev) => [...prev, { role: "user", text: userMsg }]); setInput(""); setIsTyping(true); try { const apiKey = process.env.NEXT_PUBLIC_GEMINI_API_KEY; if (!apiKey) throw new Error("API Key missing"); const systemInstruction = ` You are an elegant and helpful Wedding Concierge for a wedding celebration. Your tone is warm, respectful, and slightly formal (Indian hospitality style). Key Info: - Couple: Groom & Bride (married after 10 years of love). - Engagement: 23rd Nov 2025 at Venue Name (10:00 AM). - Wedding: 23rd Jan 2026 at Venue Name (06:00 PM). - Reception: 25th Jan 2026 at Venue Name (06:00 PM). - Story: They were college classmates who became soulmates. They love the mountains. Instructions: - Keep answers concise and polite. - If you don't know something, suggest they check the specific pages on the site. - Use "Namaste" or "Greetings" occasionally. - IMPORTANT: Provide responses in PLAIN TEXT ONLY. Do not use Markdown, bolding (**), or any other special formatting symbols. `; const response = await fetch( `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ contents: [ { role: "user", parts: [{ text: systemInstruction }] }, ...messages.map((m) => ({ role: m.role === "user" ? "user" : "model", parts: [{ text: m.text }], })), { role: "user", parts: [{ text: userMsg }] }, ], generationConfig: { maxOutputTokens: 400, temperature: 0.7 }, }), }, ); const data = await response.json(); if (data.error) { console.error("Gemini API Error Detail:", data.error); throw new Error(data.error.message); } const botResponse = data.candidates?.[0]?.content?.parts?.[0]?.text || "I apologize, I'm having trouble connecting. Please try again soon!"; setMessages((prev) => [...prev, { role: "bot", text: botResponse }]); } catch (error: any) { console.error("Chatbot Error:", error); setMessages((prev) => [ ...prev, { role: "bot", text: `I'm having a small technical issue: ${error.message || "Please try again later."}`, }, ]); } finally { setIsTyping(false); } }; return (
{isOpen && (

Wedding Assistant

Online & Ready

{messages.map((msg, i) => (
{msg.text}
))} {isTyping && (
)}
{ e.preventDefault(); handleSend(); }} > setInput(e.target.value)} />
)}
); }; export default ConciergeBot;