/* ============================================================ 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 (
{ if (e.target === e.currentTarget) onClose(); }} >
{/* Header */}
T
{CONTACT_NAME} · Baymak Yetkili Servis
Şu anda çevrimiçi · Tipik yanıt: 2 dk
{/* Messages */}
Merhaba! 👋 Servis talebinizi alabilmem için birkaç hızlı soru soracağım.

Hangi konuda yardıma ihtiyacınız var?
{step >= 1 && answers.service && ( {serviceLabel} )} {step >= 1 && !typing && ( Anladım. Ne zaman gelelim? )} {step >= 2 && answers.urgency && ( {urgencyLabel} )} {step >= 2 && !typing && ( Hangi ilçede / mahalledesiniz? )} {step >= 3 && answers.district && ( {answers.district} )} {step >= 3 && !typing && ( Son olarak iletişim için sadece adınız ve telefon numaranız yeterli. {answers.urgency === "today" && ( <>

⚡ Acil durumlarda 90 dk içinde ekibimiz kapınızda. )}
)} {step >= 4 && submitted && ( <> {answers.name} · {answers.phone} Son adım, {answers.name.split(" ")[0]}!

Mesajınız WhatsApp'ta hazır olarak açıldı. 📲 "Gönder"e basmanız yeterli — ekibimiz {answers.district} için size dönecek.

WhatsApp açılmadıysa aşağıdan tekrar deneyin:
WhatsApp'ı aç {PHONE_DISPLAY}
)} {typing && step < 5 && }
{/* Input area — varies by step */}
{step === 0 && ( {SERVICE_OPTIONS.map((s) => ( pick("service", s.id)}> {s.label} ))} )} {step === 1 && ( {URGENCY_OPTIONS.map((u) => ( pick("urgency", u.id)} hot={u.hot}> {u.label} ))} )} {step === 2 && ( {DISTRICTS.map((d) => ( pick("district", d)}>{d} ))} )} {step === 3 && ( )} {step >= 4 && !submitted && (
Gönderiliyor...
)} {submitted && ( )}
); } function Bubble({ from, success, children }) { const isBot = from === "bot"; return (
{children}
); } function TypingIndicator() { return (
{[0, 1, 2].map((i) => ( ))}
); } function OptionGrid({ children }) { return (
{children}
); } function OptionChip({ icon: I, onClick, hot, children }) { return ( ); } function ContactForm({ answers, setAnswers, onSubmit }) { const valid = answers.name.trim().length >= 2 && /\d{10,}/.test(answers.phone.replace(/\D/g, "")); return (
{ e.preventDefault(); if (valid) onSubmit(); }} style={{ display: "flex", flexDirection: "column", gap: 10 }}>
setAnswers((a) => ({ ...a, name: e.target.value }))} autoFocus required /> setAnswers((a) => ({ ...a, phone: e.target.value }))} required />
KVKK kapsamında bilgileriniz yalnızca servis talebi için kullanılır.
); } window.ChatRequest = ChatRequest;