"use client"; import type React from "react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { MessageSquare } from "lucide-react"; import { useLanguage } from "@/contexts/language-context"; import axios from "axios"; function validateContact(input: string) { const value = input.trim(); // Email regex (simple and reliable) const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Uzbek phone formats: // - 9-digit numbers: 937665544 // - +998XXXXXXXXX const phoneRegex = /^(\+998\d{9}|\d{9})$/; if (emailRegex.test(value)) { return { valid: true, type: "email" }; } if (phoneRegex.test(value)) { return { valid: true, type: "phone" }; } return { valid: false, message: "Enter valid email or phone number" }; } export default function Contact() { const [formData, setFormData] = useState({ name: "", connect_link: "", message: "", }); const { t } = useLanguage(); const [error, setError] = useState(""); const handleChange = ( e: React.ChangeEvent ) => { setFormData({ ...formData, [e.target.name]: e.target.value, }); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // Handle form submission const valid = validateContact(formData.connect_link); if (!valid.valid) { setError(valid.message || ""); return; } try { const token = "7940057045:AAHRFPvgUCo_7pqpXD6uq4li7-_DYx2J96g"; // Use environment variable const chatId = 6134458285; if (!token || !chatId) { throw new Error("Telegram token yoki chat ID topilmadi!"); } const message = ` 📥 Yangi xabar keldi! 👤 Ism: ${formData.name} 📧 Bog'lanish uchun: ${formData.connect_link} 💬 Xabar: ${formData.message} `; await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, { chat_id: chatId, text: message, }); alert("✅ Tez orada bog'lanamiz!"); setFormData({ name: "", connect_link: "", message: "", }); setError('') } catch (error) { console.error("Yuborishda xatolik:", error); alert("❌ Yuborishda xatolik yuz berdi!"); } console.log(formData); }; return (

{t.contact.title}

{t.contact.subtitle}

{/* Form */}
{error &&

{error}

}