"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: "Based in KWC. Delivering everywhere.", title: <>Ontario's B2B
Fence Supply
Partner, 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 & Stylish
Aluminum
Railing, 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 & Lasting
Composite
Fencing, 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) => (
Request a quote
Response within 2 business hours · Contractor pricing available
{alert.show && (
{alert.message}
)}
{formErrors.captcha && {formErrors.captcha}}
Or email us · info@vgfenceproducts.com
); }