import React, { useState } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; import { CalendarCheck, Link as LinkIcon } from 'lucide-react'; const SERVICE_OPTIONS = [ { value: 'foreclosure-prevention', label: 'Foreclosure Prevention' }, { value: 'fast-cash-offer', label: 'Fast Cash Offer' }, { value: 'mortgage-reinstatement', label: 'Mortgage Reinstatement' }, { value: 'general-consultation', label: 'General Real Estate Consultation' }, ]; const MAX_LEAD_DAYS = 14; const GOOGLE_APPOINTMENT_URL = import.meta.env.VITE_GOOGLE_APPOINTMENT_URL ?? ''; export interface AppointmentIntake { name: string; email: string; phone: string; propertyAddress: string; situation: string; serviceType: string; } export interface Appointment extends AppointmentIntake { id?: string; date?: string; time?: string; status?: 'pending' | 'confirmed' | 'completed' | 'cancelled'; createdAt?: string; notes?: string; } export function AppointmentScheduler() { const [formData, setFormData] = useState({ name: '', email: '', phone: '', propertyAddress: '', situation: '', serviceType: SERVICE_OPTIONS[0].value, }); const [isSubmitting, setIsSubmitting] = useState(false); const [isComplete, setIsComplete] = useState(false); const handleChange = (field: keyof AppointmentIntake, value: string) => { setFormData((prev) => ({ ...prev, [field]: value })); }; const launchGoogleSchedule = () => { if (!GOOGLE_APPOINTMENT_URL) { toast.error('Scheduling link is currently unavailable. Please call (615) 610-9857 to book.'); return; } window.open(GOOGLE_APPOINTMENT_URL, '_blank', 'noopener,noreferrer'); }; const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!formData.name || !formData.email || !formData.phone || !formData.propertyAddress || !formData.situation) { toast.error('Please fill in every field so we can prepare for your consultation.'); return; } setIsSubmitting(true); try { // Persist intake details locally so the team can follow-up if needed. const existing = JSON.parse(localStorage.getItem('intake-requests') ?? '[]') as AppointmentIntake[]; localStorage.setItem('intake-requests', JSON.stringify([...existing, formData])); toast.success('Thanks! Choose a time on the next screen to finish booking.'); setIsComplete(true); launchGoogleSchedule(); } catch (error) { console.error('Unable to store intake locally', error); toast.error('Something went wrong saving your details. Please try again or call us directly.'); } finally { setIsSubmitting(false); } }; return ( Book Your Consultation Secure a time in under a minute. Google Calendar keeps the next {MAX_LEAD_DAYS} days open, sends confirmations automatically, and reminds you before the call. {!isComplete ? (
handleChange('name', event.target.value)} placeholder="Your full name" required />
handleChange('phone', event.target.value)} placeholder="(615) 555-0123" required />
handleChange('email', event.target.value)} placeholder="you@email.com" required />
handleChange('propertyAddress', event.target.value)} placeholder="123 Main St, Nashville, TN 37212" required />