const { Button, Input, Select, Card, Icon, Badge, Checkbox } = window.FriendsCarsDesignSystem_f69f0e; const STEP_LABELS = ["Car", "Dates", "Details", "Confirm"]; function Field({ error, children }) { return (
{children} {error ? {error} : null}
); } function Row({ label, note, value, tone }) { return (
{label}{note ? {note} : null} {value}
); } function BookingScreen({ car, onOpen, onNavigate }) { const today = new Date().toISOString().slice(0, 10); const [step, setStep] = React.useState(car ? 1 : 0); const [sent, setSent] = React.useState(false); const [touched, setTouched] = React.useState(false); const [pick, setPick] = React.useState(car || null); const [from, setFrom] = React.useState(today); const [to, setTo] = React.useState(today); const [t1, setT1] = React.useState("10:00"); const [t2, setT2] = React.useState("10:00"); const [name, setName] = React.useState(""); const [phone, setPhone] = React.useState(""); const [dest, setDest] = React.useState(""); const [self, setSelf] = React.useState(true); const [wa, setWa] = React.useState(true); const [delivery, setDelivery] = React.useState("doorstep"); const [loc, setLoc] = React.useState(""); const [kms, setKms] = React.useState(""); const collect = delivery === "yard"; const q = window.quote(pick, from, t1, to, t2, kms, collect); const handover = collect ? "Collecting from us" : delivery === "airport" ? "Airport terminal" : "Doorstep in " + window.BIZ.city; /* Inline validation — no alerts. Errors only surface once a step has been attempted. */ const errs = {}; if (!pick) errs.car = "Choose a car to continue."; if (!from) errs.from = "Pickup date is required."; if (!t1) errs.t1 = "Pickup time is required."; if (!to) errs.to = "Return date is required."; if (!t2) errs.t2 = "Return time is required."; if (from && to && t1 && t2 && !window.durationHours(from, t1, to, t2)) errs.to = "Return must be after pickup."; if (!name.trim()) errs.name = "We need a name for the booking."; else if (name.trim().length < 3) errs.name = "Please enter your full name."; const digits = phone.replace(/\D/g, ""); if (!digits) errs.phone = "A mobile number is required."; else if (digits.length < 10) errs.phone = "Enter a 10-digit mobile number."; if (!dest.trim()) errs.dest = "Tell us where the car is going."; const stepErrs = [["car"], ["from", "t1", "to", "t2"], ["name", "phone", "dest"], []][step] || []; const blocked = stepErrs.filter((k) => errs[k]); const show = (k) => (touched && stepErrs.indexOf(k) > -1 ? errs[k] : null); const message = () => [ "Hello, I would like to book a car.", "", "Car: " + pick.name, "Pickup: " + window.prettyWhen(from, t1), "Return: " + window.prettyWhen(to, t2), "Duration: " + q.hours + (q.hours === 1 ? " hour" : " hours"), "Rental: " + window.rupees(q.rental) + " (" + window.rupees(q.rate) + " x " + q.days + (q.days === 1 ? " day" : " days") + ")", "Extra hours: " + q.extraHours, "Extra hour charge: " + window.rupees(q.extraCost), "Included KM: " + window.km(q.kmIncluded), "Pickup & Drop: " + (collect ? "Not required — collecting from you" : (loc.trim() || handover) + (kms ? " (" + kms + " KM)" : "")), "Pickup & Drop Charge: " + (q.pd.over ? "On request — beyond 20 KM" : q.pd.set ? window.rupees(q.pdCharge) : "Not applicable"), "Security Deposit: " + window.rupees(q.deposit) + " (refundable)", "Estimated Rental: " + window.rupees(q.estRental), "", "Name: " + name.trim(), "Mobile: " + phone.trim(), "Where are you going: " + dest.trim(), "", self ? "I am the person who will drive the car." : "Another named driver will drive the car.", wa ? "Please send the confirmation on WhatsApp." : "", "Please confirm availability and booking details." ].filter(Boolean).join("\n"); const waLink = () => "https://wa.me/" + window.BIZ.waBook + "?text=" + encodeURIComponent(message()); const advance = () => { if (blocked.length) { setTouched(true); return; } setTouched(false); setStep((s) => Math.min(3, s + 1)); }; const send = () => { const bad = ["car", "from", "t1", "to", "t2", "name", "phone", "dest"].filter((k) => errs[k]); if (bad.length) { setTouched(true); setStep(errs.car ? 0 : (errs.from || errs.t1 || errs.to || errs.t2) ? 1 : 2); return; } window.open(waLink(), "_blank", "noopener"); setSent(true); }; const back = () => { setTouched(false); setStep((s) => Math.max(0, s - 1)); }; const goto = (n) => { if (n <= step) { setTouched(false); setStep(n); } }; const extraNote = q.extraHours ? q.extraHours + (q.extraHours === 1 ? " hour" : " hours") + " × " + window.rupees(q.extraRate) : ""; return (
    {STEP_LABELS.map((s, i) => (
  1. ))}
{step === 0 ? ( {touched && errs.car ?
{errs.car}
: null}
{window.FLEET.map((c) => ( ))}
) : null} {step === 1 ? (
setFrom(e.target.value)} /> setT1(e.target.value)} /> setTo(e.target.value)} /> setT2(e.target.value)} />
{q.hours ? "That is " + window.prettyDuration(q) + ". Each rate covers a complete 24-hour period; extra hours are " + window.rupees(q.extraRate) + " each on this car." : "Set both dates and times to see the estimate."}
setLoc(e.target.value)} />} {collect ? null : setKms(e.target.value)} />}
{q.pd.over ?
{window.PICKUP.beyond}
: null}
) : null} {step === 2 ? (
setName(e.target.value)} /> setPhone(e.target.value)} />
setDest(e.target.value)} />
setSelf(e.target.checked)} /> setWa(e.target.checked)} />
) : null} {step === 3 && !sent ? ( Review your booking
{q.extraHours ? : null}

{window.BIZ.depositNote}

Opens WhatsApp with the details filled in. Nothing is sent until you press send there.
) : null} {sent ? ( Request opened in WhatsApp

{pick.name} — {window.prettyDuration(q)}, {window.rupees(q.estRental)} estimated.

Press send in WhatsApp and one of us will confirm on {phone.trim()} shortly. Deposit of {window.rupees(q.deposit)} is refundable and nothing has been charged here.

) : null} {!sent && step < 3 ? (
) : null}
); } Object.assign(window, { BookingScreen });