/* global React, Ic, useT */ const { useState } = React; const SUPPORT_IDS = ["activity", "restaurant", "transport", "language", "planning", "fixer"]; const GROUP_TYPE_IDS = ["stag", "friends", "corp", "sports", "bday", "event", "other"]; function RequestForm() { const { t } = useT(); const STEP_TITLES = [t("form.step.basics"), t("form.step.group"), t("form.step.plan"), t("form.step.review")]; const GROUP_TYPES = GROUP_TYPE_IDS.map((id) => ({ id, label: t("form.gt." + id) })); const SUPPORT_OPTIONS = SUPPORT_IDS.map((id) => ({ id, label: t("form.sup." + id) })); const LANGUAGES = [ { v: "English", label: "English" }, { v: "Latvian", label: "Latvian" }, { v: "Any", label: t("form.lang.any") }, ]; const [step, setStep] = useState(0); const [done, setDone] = useState(false); const [submitting, setSubmitting] = useState(false); const [touched, setTouched] = useState({}); const [data, setData] = useState({ name: "", contact: "", date: "", size: "", type: "", activities: "", support: [], language: "English", notes: "", }); const set = (k, v) => setData((d) => ({ ...d, [k]: v })); const toggleSupport = (id) => setData((d) => ({ ...d, support: d.support.includes(id) ? d.support.filter((x) => x !== id) : [...d.support, id], })); // validation per step const errors = (() => { const e = {}; if (step === 0) { if (!data.name.trim()) e.name = t("form.err.name"); if (!data.contact.trim()) e.contact = t("form.err.contact_required"); else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.contact) && !/^[+0-9\s\-()]{7,}$/.test(data.contact)) e.contact = t("form.err.contact_format"); if (!data.date) e.date = t("form.err.date"); } if (step === 1) { const n = parseInt(data.size, 10); if (!data.size) e.size = t("form.err.size_required"); else if (isNaN(n) || n < 2) e.size = t("form.err.size_number"); else if (n > 200) e.size = t("form.err.size_max"); if (!data.type) e.type = t("form.err.type"); } if (step === 2) { if (!data.activities.trim()) e.activities = t("form.err.acts"); if (data.support.length === 0) e.support = t("form.err.support"); } return e; })(); const canAdvance = Object.keys(errors).length === 0; const next = () => { const fieldsByStep = [ ["name", "contact", "date"], ["size", "type"], ["activities", "support"], ]; const fields = fieldsByStep[step] || []; setTouched((tt) => ({ ...tt, ...Object.fromEntries(fields.map((f) => [f, true])) })); if (!canAdvance) return; if (step < 3) setStep(step + 1); }; const back = () => { if (step > 0) setStep(step - 1); }; const submit = () => { setSubmitting(true); setTimeout(() => { setSubmitting(false); setDone(true); }, 900); }; const reset = () => { setDone(false); setStep(0); setTouched({}); setData({ name: "", contact: "", date: "", size: "", type: "", activities: "", support: [], language: "English", notes: "" }); }; const groupTypeLabel = data.type ? (GROUP_TYPES.find((g) => g.id === data.type) || {}).label : ""; const supportLabels = data.support.map((id) => SUPPORT_OPTIONS.find((o) => o.id === id).label).join(", "); return (
{t("form.eyebrow")}

{t("form.title_l1")}
{t("form.title_l2")}
{t("form.title_em")}

{t("form.p1")}

{t("form.p2")}

{t("form.trust1")} {t("form.trust2")} {t("form.trust3")}
{done ? ( ) : ( <> {step === 0 && (

{STEP_TITLES[step]}

{t("form.basics.hint")}

set("name", e.target.value)} onBlur={() => setTouched((tt) => ({ ...tt, name: true }))} /> {touched.name && errors.name && {errors.name}}
set("contact", e.target.value)} onBlur={() => setTouched((tt) => ({ ...tt, contact: true }))} /> {touched.contact && errors.contact && {errors.contact}}
set("date", e.target.value)} onBlur={() => setTouched((tt) => ({ ...tt, date: true }))} /> {touched.date && errors.date && {errors.date}}
)} {step === 1 && (

{STEP_TITLES[step]}

{t("form.group.hint")}

set("size", e.target.value)} onBlur={() => setTouched((tt) => ({ ...tt, size: true }))} /> {touched.size && errors.size && {errors.size}}
{GROUP_TYPES.map((g) => ( ))}
{touched.type && errors.type && {errors.type}}
)} {step === 2 && (

{STEP_TITLES[step]}

{t("form.plan.hint")}