/* ============================================================ ChatRequest — chat-style servis talep akışı (modal) ============================================================ */ const SERVICE_OPTIONS = [ { id: "kombi-ariza", label: "Kombi arızası", icon: Icon.Flame }, { id: "kombi-bakim", label: "Kombi bakımı / onarım", icon: Icon.Tool }, { id: "kazan", label: "Yoğuşmalı kazan", icon: Icon.Spark }, { id: "hidrofor", label: "Hidrofor", icon: Icon.Droplet }, { id: "klima", label: "Klima montaj / arıza", icon: Icon.Snowflake }, { id: "petek", label: "Petek tesisatı yıkama", icon: Icon.Droplet }, { id: "yedek", label: "Orijinal yedek parça", icon: Icon.Badge }, { id: "diger", label: "Diğer / emin değilim", icon: Icon.Spark }, ]; const URGENCY_OPTIONS = [ { id: "today", label: "Bugün — kombi çalışmıyor", hot: true }, { id: "tomorrow", label: "Yarın olabilir" }, { id: "week", label: "Bu hafta içinde" }, { id: "flexible", label: "Esnek, planlayalım" }, ]; const DISTRICTS = [ "Kars Merkez", "Selim", "Kağızman", "Susuz", "Arpaçay", "Akyaka", "Digor", ]; function ChatRequest({ open, onClose, initialService = null }) { const [step, setStep] = React.useState(0); const [answers, setAnswers] = React.useState({ service: null, urgency: null, district: null, brand: "", name: "", phone: "", }); const [typing, setTyping] = React.useState(false); const [submitted, setSubmitted] = React.useState(false); const scrollRef = React.useRef(null); const messagesEndRef = React.useRef(null); React.useEffect(() => { if (open && initialService) { setAnswers((a) => ({ ...a, service: initialService })); setStep(1); } }, [open, initialService]); React.useEffect(() => { if (!open) { // reset on close const t = setTimeout(() => { setStep(0); setAnswers({ service: null, urgency: null, district: null, brand: "", name: "", phone: "" }); setSubmitted(false); }, 250); return () => clearTimeout(t); } }, [open]); React.useEffect(() => { // simulate typing dot on step change setTyping(true); const t = setTimeout(() => setTyping(false), 650); return () => clearTimeout(t); }, [step, open]); React.useEffect(() => { if (messagesEndRef.current) { messagesEndRef.current.scrollIntoView({ behavior: "smooth", block: "end" }); } }, [step, typing, submitted]); if (!open) return null; const pick = (key, value, autoAdvance = true) => { setAnswers((a) => ({ ...a, [key]: value })); if (autoAdvance) setTimeout(() => setStep((s) => s + 1), 200); }; const serviceLabel = answers.service ? SERVICE_OPTIONS.find((s) => s.id === answers.service)?.label : null; const urgencyLabel = answers.urgency ? URGENCY_OPTIONS.find((s) => s.id === answers.urgency)?.label : null; const submit = () => { // Build WhatsApp message const lines = [ "Merhaba Taner Elektronik 👋", "", "Servis talebim:", `• Hizmet: ${serviceLabel || "—"}`, `• Aciliyet: ${urgencyLabel || "—"}`, `• İlçe / Bölge: ${answers.district || "—"}`, `• Ad Soyad: ${answers.name}`, `• Telefon: ${answers.phone}`, "", "Geri dönüşünüzü bekliyorum.", ]; const text = encodeURIComponent(lines.join("\n")); const waUrl = `https://wa.me/905541939736?text=${text}`; window.open(waUrl, "_blank", "noopener,noreferrer"); setSubmitted(true); setStep(5); }; return (