"use client"; import React, { useState, useEffect } from "react"; import ReCAPTCHA from "react-google-recaptcha"; import axios from "axios"; import Link from 'next/link'; const slides = [ { id: 0, eyebrow: "Kitchener · Waterloo · Ontario · 250km delivery radius", title: <>Ontario's B2BFence SupplyPartner>, sub: <>Supplying contractors, builders, and property managers across Ontario with chain link, ornamental, composite, glass railing, aluminum railing, Expert Stain & Seal, Fence Armor, and temporary fence rental — with scheduled job site delivery across a 250km radius from KWC.>, productValue: "", }, { id: 1, eyebrow: "Premium Aluminum Railing Systems", title: <>Durable & StylishAluminumRailing>, sub: <>High-quality, easy-to-install aluminum railing systems for residential and commercial projects. Available in multiple styles and colors with fast job site delivery across our service area.>, productValue: "Aluminum railing", }, { id: 2, eyebrow: "Low Maintenance Composite Fencing", title: <>Modern & LastingCompositeFencing>, sub: <>Provide your clients with beautiful, weather-resistant composite fences. Easy installation, long lifespan, and premium aesthetics for any property.>, productValue: "Composite fence", } ]; export default function Hero() { const [formData, setFormData] = useState({ company: "", name: "", phone: "", email: "", product: "", city: "", quantity: "" }); const [formErrors, setFormErrors] = useState({}); const [captchaToken, setCaptchaToken] = useState(null); const [alert, setAlert] = useState({ show: false, type: "", message: "" }); const [currentSlide, setCurrentSlide] = useState(0); const [userSelectedProduct, setUserSelectedProduct] = useState(false); useEffect(() => { const timer = setInterval(() => { setCurrentSlide((prev) => (prev + 1) % slides.length); }, 6000); return () => clearInterval(timer); }, []); useEffect(() => { if (!userSelectedProduct) { setFormData((prev) => ({ ...prev, product: slides[currentSlide].productValue })); } }, [currentSlide, userSelectedProduct]); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; if (name === "product") { setUserSelectedProduct(true); } setFormData((prev) => ({ ...prev, [name]: value })); }; const handleCaptchaChange = (token: string | null) => { setCaptchaToken(token); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); const errors: any = {}; if (!formData.name.trim()) errors.name = "Name is required."; if (!formData.phone.trim()) errors.phone = "Phone is required."; if (!formData.email.trim()) errors.email = "Email is required."; if (!formData.product.trim()) errors.product = "Please select a product."; if (!captchaToken) errors.captcha = "Please verify the CAPTCHA."; setFormErrors(errors); if (Object.keys(errors).length > 0) return; const emailData = { name: formData.name, email: formData.email, phone: formData.phone, message: ` Company: ${formData.company} Product: ${formData.product} Job Site City: ${formData.city} Quantity: ${formData.quantity} `, to: "info@vgfenceproducts.com", senderName: "VG Fence Hero Form", recaptchaToken: captchaToken, }; setAlert({ show: true, type: "info", message: "Sending your request..." }); try { await axios.post("https://mailserver.metatronnest.com/send", emailData, { headers: { "Content-Type": "application/json" }, }); setAlert({ show: true, type: "success", message: "Thank you! Your quote request has been sent successfully.", }); setFormData({ company: "", name: "", phone: "", email: "", product: "", city: "", quantity: "" }); setCaptchaToken(null); setFormErrors({}); } catch (error) { console.error("❌ Error sending email:", error); setAlert({ show: true, type: "danger", message: "Failed to send request. Please try again later.", }); } }; useEffect(() => { if (alert.show && alert.type !== "info") { const timer = setTimeout(() => { setAlert((prev) => ({ ...prev, show: false })); }, 5000); return () => clearTimeout(timer); } }, [alert.show, alert.type]); return ( {slides[currentSlide].eyebrow} {slides[currentSlide].title} {slides[currentSlide].sub} Request contractor pricing View all products {slides.map((_, i) => ( setCurrentSlide(i)} className={`hero-slider-dot ${currentSlide === i ? 'active' : ''}`} aria-label={`Go to slide ${i + 1}`} /> ))} Request a quote Response within 2 business hours · Contractor pricing available {alert.show && ( {alert.message} )} Company name Your name Phone Email Product needed Select a product or service... Aluminum railing Chain link fence — commercial Chain link fence — residential Composite fence Expert Stain & Seal products Fence Armor (post caps / guards) Glass railing Ornamental / iron fence Temporary fence rental — construction Temporary fence rental — event Wood staining service 2D fence drawing services Contractor account enquiry Multiple products Job site city Approx. quantity I have read and agree to VG Fence Products' Terms & Conditions, Delivery Policy, and Photo Verification (24hr) Policy. I understand that damage claims require photos submitted within 24 hours of delivery. {formErrors.captcha && {formErrors.captcha}} {alert.type === "info" ? "Sending..." : "Send quote request →"} Or email us · info@vgfenceproducts.com ); }
{slides[currentSlide].sub}