"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { LoaderIcon } from "lucide-react"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { z } from "zod"; import { Button } from "@/components/ui/button"; import { Field, FieldError, FieldGroup, FieldLabel, } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { cn } from "@/lib/utils"; const contactFormSchema = z.object({ name: z.string().min(1, "نام الزامی است"), email: z .string() .min(1, "ایمیل الزامی است") .email("آدرس ایمیل نامعتبر است"), message: z.string().min(1, "پیام الزامی است"), }); type ContactFormData = z.infer; interface Location { id: string; name: string; address: string; city: string; phone: string; email: string; mapQuery: string; } interface Contact22Props { title?: string; description?: string; locations?: Location[]; className?: string; onSubmit?: (data: ContactFormData) => Promise; } const Contact22 = ({ title = "دفاتر منطقه‌ای فروش", description = "نزدیک‌ترین دفتر سازمانی را انتخاب کنید یا فرم را پر کنید تا تیم فروش و موفقیت مشتری پیگیری کنند.", locations = [ { id: "tehran", name: "تهران — دفتر تهران", address: "Valiasr St, District 6", city: "Tehran, Iran", phone: "۲۱-۱۲۳۴۵۶۷۸", email: "tehran@lawfirm.com", mapQuery: "Valiasr Street, Tehran, Iran", }, { id: "nyc", name: "نیویورک — آمریکای شمالی", address: "350 Fifth Avenue, Suite 4200", city: "New York, NY 10118", phone: "+1 (212) 555-0123", email: "nyc@lawfirm.com", mapQuery: "Empire State Building, New York, NY", }, { id: "la", name: "لس‌آنجلس — ساحل غربی", address: "633 West 5th Street, Suite 2600", city: "Los Angeles, CA 90071", phone: "+1 (213) 555-0456", email: "la@lawfirm.com", mapQuery: "633 West 5th Street, Los Angeles, CA", }, { id: "chicago", name: "شیکاگو — میدوست", address: "233 South Wacker Drive, Suite 8400", city: "Chicago, IL 60606", phone: "+1 (312) 555-0789", email: "chicago@lawfirm.com", mapQuery: "Willis Tower, Chicago, IL", }, { id: "miami", name: "میامی — جنوب شرقی", address: "1395 Brickell Avenue, Suite 800", city: "Miami, FL 33131", phone: "+1 (305) 555-0234", email: "miami@lawfirm.com", mapQuery: "1395 Brickell Avenue, Miami, FL", }, { id: "boston", name: "بوستون — شمال شرقی", address: "100 Federal Street, Suite 2000", city: "Boston, MA 02110", phone: "+1 (617) 555-0567", email: "boston@lawfirm.com", mapQuery: "100 Federal Street, Boston, MA", }, ], className, onSubmit, }: Contact22Props) => { const [selectedLocation, setSelectedLocation] = useState( locations[0], ); const [isSubmitted, setIsSubmitted] = useState(false); const [showSuccess, setShowSuccess] = useState(false); const form = useForm({ resolver: zodResolver(contactFormSchema), mode: "onSubmit", reValidateMode: "onSubmit", defaultValues: { name: "", email: "", message: "", }, }); const handleFormSubmit = async (data: ContactFormData) => { try { if (onSubmit) { await onSubmit(data); } else { console.log("Form submitted:", data); await new Promise((resolve) => setTimeout(resolve, 1000)); } setIsSubmitted(true); setShowSuccess(true); form.reset(); setTimeout(() => setShowSuccess(false), 4500); setTimeout(() => setIsSubmitted(false), 5000); } catch { form.setError("root", { message: "ارسال ناموفق بود. لطفاً دوباره تلاش کنید.", }); } }; return (

{title}

{description}

{locations.map((location) => ( ))}