/* global React */ function Wizard({ state, update, onExit, onSubmit }) { const visibleSteps = stepsFor(state.category); const [current, setCurrent] = React.useState("category"); const [sheetOpen, setSheetOpen] = React.useState(false); React.useEffect(() => { if (!visibleSteps.includes(current)) setCurrent("category"); }, [state.category]); const idx = Math.max(visibleSteps.indexOf(current), 0); const isLast = current === "seller"; function validStep(step) { if (step === "category") return !!state.category; if (step === "type") { const isFree = state.category === "accessories" || state.category === "technology"; if (isFree) return (state.type || "").trim().length >= 2; if (state.category === "luggage" && state.type === "other") return state.customType.trim().length >= 2; return !!state.type; } if (step === "size") { if (state.category === "luggage") return String(state.size).length > 0; if (state.category === "riding-gears" && state.type === "boots") return !!state.size && !!state.sizeSystem; return !!state.size; } if (step === "details") { if (state.category === "motorcycle") return !!state.brand && !!state.model && !!state.mfgYear && !!state.condition; return !!state.brand && !!state.condition; } if (step === "price") return Number(state.price) > 0 && state.location.trim().length > 1; if (step === "photos") return (state.photos?.length || 0) >= 1; if (step === "reason") return state.description.trim().length >= 10; if (step === "seller") return state.sellerName.trim().length >= 2 && state.sellerPhone.trim().length >= 8 && state.consent; return true; } function next() { const nextIdx = idx + 1; if (nextIdx < visibleSteps.length) setCurrent(visibleSteps[nextIdx]); window.scrollTo({ top: 0, behavior: "smooth" }); } function prev() { if (idx > 0) setCurrent(visibleSteps[idx - 1]); else onExit(); window.scrollTo({ top: 0, behavior: "smooth" }); } const StepEl = { category: StepCategory, type: StepType, size: StepSize, details: StepDetails, price: StepPrice, photos: StepPhotos, reason: StepReason, seller: StepSeller, }[current]; return (
We've recorded your listing and it's now on its way to the Garage Sale WhatsApp group.