"use client"; import { useState } from "react"; import { motion } from "framer-motion"; import { Phone, MessageSquare, MapPin } from "lucide-react"; import Image from "next/image"; import { useLanguage } from "@/context/language-context"; import { useProductStore } from "@/lib/productZustand"; import axios from "axios"; export function ContactForm() { const { t } = useLanguage(); const productName = useProductStore((state) => state.productName); const reset = useProductStore((state) => state.resetProductName); const [formData, setFormData] = useState({ name: "", phone: "", message: "", productName: "", }); const [loading, setLoading] = useState(false); const [message, setMessage] = useState<{ type: "success" | "error"; text: string; } | null>(null); const phoneRegex = /^\+?\d*$/; // + majburiy const handleChange = ( e: React.ChangeEvent< HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement > ) => { const { name, value } = e.target; if (name === "phone") { // regexga mos kelmasa — state o‘zgarmaydi if (!phoneRegex.test(value)) return; setFormData((prev) => ({ ...prev, phone: value, })); } else { setFormData((prev) => ({ ...prev, [name]: value, })); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setMessage(null); const text = ` 📩 New Contact Message 👤 Name: ${formData.name} 📞 Phone: ${formData.phone} 📦 Product: ${formData.productName || "—"} 💬 Message: ${formData.message || "—"} `; try { const token = "8242045471:AAHaECS0psWg1jGBaIk1GxxTG6sBAssK_vw"; // Use environment variable const chatId = 6134458285; await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, { chat_id: chatId, text: text, }); setMessage({ type: "success", text: t.contact.success }); reset(); setFormData({ name: "", phone: "", message: "", productName: "" }); } catch { setMessage({ type: "error", text: t.contact.error }); } finally { setLoading(false); } }; return (
hero image
{/* Header */}

{t.contact.title}

{/* Contact Info */}

{t.contact.title}

{t.contact.desc}

{/* Contact Methods */} {[ { icon: Phone, title: "phone_title", value: "+998 (99) 869-74-70", }, { icon: MessageSquare, title: "telegram_title", value: "@firma_support", }, { icon: MapPin, title: "addres_title", value: "Tashkent, Сергели 6 а 179 кв", }, ].map((item, idx) => { const Icon = item.icon; return (

{t.contact[item.title]}

{item.value}

); })}
{/* Form */} {/* Name */}
{/* Phone */}
{/* Message */}