"use client"; import Image from "next/image"; import { Card, CardBody, Button, Snippet, Input, Textarea, Divider, Spinner, Avatar, addToast, Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, useDisclosure, } from "@heroui/react"; import { useEffect, useState } from "react"; import { getFirestore, collection, addDoc, onSnapshot, query, orderBy, serverTimestamp, limit, deleteDoc, doc, } from "firebase/firestore"; import { getAuth, onAuthStateChanged, User } from "firebase/auth"; import { motion, AnimatePresence } from "framer-motion"; import firebaseApp from "@/config/firebase"; import { fontCursive, fontSans, fontMono } from "@/config/fonts"; import { HeartFilledIcon, TrashIcon } from "@/components/icons"; const db = getFirestore(firebaseApp()); export default function SagunPage() { const [wishes, setWishes] = useState([]); const [loading, setLoading] = useState(true); const [submitting, setSubmitting] = useState(false); const [user, setUser] = useState(null); const [formData, setFormData] = useState({ name: "", message: "", captcha: "", }); const [sentiment, setSentiment] = useState(""); const { isOpen, onOpen, onOpenChange } = useDisclosure(); const [wishToDelete, setWishToDelete] = useState(null); useEffect(() => { const auth = getAuth(firebaseApp()); const unsubscribeAuth = onAuthStateChanged(auth, (currentUser) => { setUser(currentUser); }); const q = query( collection(db, "wishes"), orderBy("createdAt", "desc"), limit(20), ); const unsubscribeFirestore = onSnapshot(q, (snapshot) => { const data = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() })); setWishes(data); setLoading(false); if (data.length >= 3) { generateSentimentSummary(data.slice(0, 10)); } }); return () => { unsubscribeAuth(); unsubscribeFirestore(); }; }, []); const handleDeleteWish = async () => { if (!wishToDelete) return; try { await deleteDoc(doc(db, "wishes", wishToDelete)); addToast({ title: "Wish Deleted", description: "The blessing has been removed.", color: "warning", }); setWishToDelete(null); } catch (err) { console.error("Error deleting wish", err); } }; const confirmDelete = (id: string) => { setWishToDelete(id); onOpen(); }; const generateSentimentSummary = async (recentWishes: any[]) => { const apiKey = process.env.NEXT_PUBLIC_GEMINI_API_KEY; if (!apiKey) return; try { 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: [ { parts: [ { text: `You are a wedding storyteller. Summarize the following guest wishes into a single, beautiful, and poetic paragraph (max 250 characters) that captures the collective love and blessings for the couple. Output ONLY the paragraph in PLAIN TEXT.`, }, { text: `Wishes: ${recentWishes.map((w) => w.message).join(" | ")}`, }, ], }, ], generationConfig: { temperature: 0.7, maxOutputTokens: 150 }, }), }, ); const result = await response.json(); const text = result.candidates?.[0]?.content?.parts?.[0]?.text; if (text) setSentiment(text); } catch (err) { console.error("Sentiment error", err); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // Simple Wedding-Themed Bot Protection if (formData.captcha.trim() !== "10") { addToast({ title: "Security Check", description: "Please answer the question correctly (Hint: It is a number!).", color: "warning", }); return; } if (!formData.name || !formData.message) return; setSubmitting(true); try { await addDoc(collection(db, "wishes"), { name: formData.name, message: formData.message, createdAt: serverTimestamp(), }); setFormData({ name: "", message: "", captcha: "" }); addToast({ title: "Wish Sent", description: "Thank you for your beautiful blessings!", color: "success", }); } catch (err) { console.error("Error adding wish", err); addToast({ title: "Error", description: "Something went wrong. Please try again.", color: "danger", }); } finally { setSubmitting(false); } }; return (
{/* Header */}

Blessings & Sagun

Your love and presence are the greatest gifts we could ask for. Share your blessings and wishes with us as we begin our new journey together.

{/* QR & UPI Section */}
{/* QR Card */}
Sagun QR Code

Scan to Bless

{/* UPI Details */}

UPI Details

You can use any UPI app to send your token of love directly.

your-upi-id@upi
{/* Wishes Section */}
{/* Wish Form */}

Leave a Wish

Your words will be cherished forever. Write a small message for the couple.

setFormData({ ...formData, name: e.target.value }) } />