// Multi-step quote form const { useState: useStateForm } = React; function QuoteForm({ lang, onDone }) { const [step, setStep] = useState(0); const [data, setData] = useState({ machine: "", height: "", rental: "", duration: "", name: "", company: "", phone: "", email: "", startDate: "", city: "Ankara", details: "", }); const [errs, setErrs] = useState({}); const [done, setDone] = useState(false); const [ref, setRef] = useState(""); const [submitting, setSubmitting] = useState(false); const [submitErr, setSubmitErr] = useState(""); const T = lang === "tr" ? { steps: ["MAKİNE", "SÜRE", "İLETİŞİM", "ONAY"], next: "Devam", back: "Geri", submit: "Teklif İste", stepOf: (a, b) => `Adım ${a} / ${b}`, machineQ: "Hangi makineyi istiyorsun?", machineSub: "İhtiyaca en yakın türü seç.", machines: [ { v: "Makaslı Platform", s: "Dikey · 6–18 m" }, { v: "Eklemli Platform", s: "Engel üstü · 12–43 m" }, { v: "Teleskopik Platform", s: "Düz uzun · 18–58 m" }, { v: "Sepetli Platform", s: "Araç üstü · 20–105 m" }, { v: "Forklift", s: "1.5 – 10 ton" }, { v: "Karar vermedim", s: "Danışmanla konuş" }, ], heightQ: "Yaklaşık yükseklik?", heights: ["0–10 m", "10–20 m", "20–40 m", "40+ m"], rentalQ: "Nasıl kiralamak istiyorsun?", rentals: [ { v: "Operatörlü", s: "SRC belgeli sürücü dahil" }, { v: "Kuru (operatörsüz)", s: "Kullanıcı eğitimi dahil" }, ], durationQ: "Kiralama süresi?", durations: ["Günlük", "Haftalık", "Aylık", "Proje (3+ ay)"], infoTitle: "Seninle nasıl iletişime geçelim?", fields: { name: "Ad Soyad", company: "Firma", phone: "Telefon", email: "E-mail", startDate: "Başlangıç Tarihi", city: "Şehir", details: "Ek notlar", }, confirmTitle: "Özet", confirmSub: "Gönderdikten sonra 30 dk içinde dönüyoruz.", successT: "Teklif talebi alındı.", successS: "Uzmanımız 30 dakika içinde telefondan geri dönecek. Acil durumlarda aşağıdaki numarayı arayabilirsin.", successRef: "Referans", errReq: "Zorunlu alan", errEmail: "Geçersiz e-mail", } : { steps: ["MACHINE", "PERIOD", "CONTACT", "REVIEW"], next: "Next", back: "Back", submit: "Request Quote", stepOf: (a, b) => `Step ${a} / ${b}`, machineQ: "Which machine do you need?", machineSub: "Pick the closest type.", machines: [ { v: "Scissor Lift", s: "Vertical · 6–18 m" }, { v: "Articulating Boom", s: "Over-obstacle · 12–43 m" }, { v: "Telescopic Boom", s: "Long straight · 18–58 m" }, { v: "Truck-Mounted", s: "Truck basket · 20–105 m" }, { v: "Forklift", s: "1.5 – 10 ton" }, { v: "Not sure yet", s: "Talk to an advisor" }, ], heightQ: "Approx. height?", heights: ["0–10 m", "10–20 m", "20–40 m", "40+ m"], rentalQ: "Rental type?", rentals: [ { v: "Operated", s: "SRC certified driver included" }, { v: "Dry (no operator)", s: "User training included" }, ], durationQ: "Rental period?", durations: ["Daily", "Weekly", "Monthly", "Project (3+ mo)"], infoTitle: "How should we reach you?", fields: { name: "Full name", company: "Company", phone: "Phone", email: "Email", startDate: "Start date", city: "City", details: "Notes", }, confirmTitle: "Summary", confirmSub: "We'll call back within 30 minutes.", successT: "Quote request received.", successS: "Our specialist will call you back within 30 minutes. For urgent requests please call the number below.", successRef: "Reference", errReq: "Required", errEmail: "Invalid email", }; const setField = (k, v) => setData(d => ({ ...d, [k]: v })); const validate = () => { const e = {}; if (step === 0) { if (!data.machine) e.machine = T.errReq; if (!data.height) e.height = T.errReq; } else if (step === 1) { if (!data.rental) e.rental = T.errReq; if (!data.duration) e.duration = T.errReq; } else if (step === 2) { if (!data.name) e.name = T.errReq; if (!data.phone) e.phone = T.errReq; if (data.email && !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(data.email)) e.email = T.errEmail; } setErrs(e); return Object.keys(e).length === 0; }; const next = () => { if (!validate()) return; if (step < 3) setStep(s => s + 1); }; const back = () => setStep(s => Math.max(0, s - 1)); const submit = async () => { setSubmitting(true); setSubmitErr(""); try { const body = new URLSearchParams({ name: data.name, phone: data.phone, email: data.email, company: data.company, city: data.city, machine: data.machine, height: data.height, rental: data.rental, duration: data.duration, startDate: data.startDate, message: data.details, }); const res = await fetch("send_mail.php", { method: "POST", body }); const json = await res.json(); if (json.ok) { const r = "AVK-" + Math.random().toString(36).slice(2, 7).toUpperCase() + "-" + new Date().getFullYear(); setRef(r); setDone(true); } else { setSubmitErr(json.error || (lang === "tr" ? "Gönderim başarısız." : "Submission failed.")); } } catch (e) { setSubmitErr(lang === "tr" ? "Bağlantı hatası. Lütfen telefon ile arayın." : "Connection error. Please call us directly."); } finally { setSubmitting(false); } }; if (done) { return (

{T.successT}

{T.successS}

{T.successRef}: {ref}
0312 395 58 62
); } return (
{T.steps.map((s, i) => (
0{i+1} · {s}
))}
{step === 0 && ( <>
{T.machines.map(m => (
setField("machine", m.v)}>
{m.v}
{m.s}
))}
{errs.machine &&
{errs.machine}
}
{T.heights.map(h => (
setField("height", h)}>
{h}
))}
{errs.height &&
{errs.height}
}
)} {step === 1 && ( <>
{T.rentals.map(m => (
setField("rental", m.v)}>
{m.v}
{m.s}
))}
{errs.rental &&
{errs.rental}
}
{T.durations.map(h => (
setField("duration", h)}>
{h}
))}
{errs.duration &&
{errs.duration}
}
)} {step === 2 && ( <>
setField("name", e.target.value)} /> {errs.name &&
{errs.name}
}
setField("company", e.target.value)} />
setField("phone", e.target.value)} placeholder="0555 000 00 00" /> {errs.phone &&
{errs.phone}
}
setField("email", e.target.value)} /> {errs.email &&
{errs.email}
}
setField("startDate", e.target.value)} />