"use client"; import { motion } from "motion/react"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { ArrowRight } from "lucide-react"; import { useState } from "react"; import { toast } from "sonner"; import Image from "next/image"; import { Handlebars } from "./handlebars"; interface HeroProps { signupCount: number; } export function Hero({ signupCount }: HeroProps) { const [email, setEmail] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!email.trim()) { toast.error("Email required", { description: "Please enter your email address.", }); return; } setIsSubmitting(true); try { const response = await fetch("/api/waitlist", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ email: email.trim() }), }); const data = (await response.json()) as { error: string }; if (response.ok) { toast.success("Welcome to the waitlist! 🎉", { description: "You'll be notified when we launch.", }); setEmail(""); } else { toast.error("Oops!", { description: (data as { error: string }).error || "Something went wrong. Please try again.", }); } } catch (error) { toast.error("Network error", { description: "Please check your connection and try again.", }); } finally { setIsSubmitting(false); } }; return (