"use client"; import { FormEvent, useState } from "react"; import { ArrowLeft } from "lucide-react"; export function ContactForm() { const [error, setError] = useState(""); const [success, setSuccess] = useState(""); const [sending, setSending] = useState(false); async function submit(event: FormEvent) { event.preventDefault(); const formElement = event.currentTarget; const form = new FormData(formElement); const name = String(form.get("name") ?? "").trim(); const phone = String(form.get("phone") ?? "").trim(); const subject = String(form.get("subject") ?? "").trim(); const message = String(form.get("message") ?? "").trim(); if (!name || !phone || !subject || !message) { setError("لطفا نام، شماره تماس، موضوع و متن پیام را کامل کنید."); return; } setError(""); setSuccess(""); setSending(true); try { const response = await fetch("/api/contact", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: subject, name, cellNumber: phone, text: message, }), }); if (!response.ok) throw new Error("Contact submission failed"); formElement.reset(); setSuccess("پیام شما با موفقیت ثبت شد. همکاران ما با شما تماس می‌گیرند."); } catch { setError("ارسال پیام انجام نشد. لطفا دوباره تلاش کنید."); } finally { setSending(false); } } return (