// Scheduler.jsx — Calendly-style calendar + time slots + booking + payment (i18n)

function getMonthDays(year, month) {
  const first = new Date(year, month, 1);
  const last = new Date(year, month + 1, 0);
  const startDow = first.getDay();
  const days = [];
  for (let i = 0; i < startDow; i++) days.push(null);
  for (let d = 1; d <= last.getDate(); d++) days.push(d);
  while (days.length % 7 !== 0) days.push(null);
  return days;
}

const Scheduler = ({ paymentModel = "deposit", t }) => {
  const today = new Date(2026, 3, 24);
  const [step, setStep] = React.useState(1);
  const [serviceId, setServiceId] = React.useState("diag");
  const [viewMonth, setViewMonth] = React.useState(today.getMonth());
  const [viewYear, setViewYear] = React.useState(today.getFullYear());
  const [selectedDate, setSelectedDate] = React.useState(null);
  const [selectedSlot, setSelectedSlot] = React.useState(null);
  const [details, setDetails] = React.useState({ name: "", email: "", phone: "", address: "", notes: "" });
  const [card, setCard] = React.useState({ number: "", exp: "", cvc: "", zip: "" });
  const [processing, setProcessing] = React.useState(false);
  const [payError, setPayError] = React.useState(null);

  React.useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    const paid = params.get("paid");
    const cancelled = params.get("cancelled");
    if (!paid && !cancelled) return;

    try {
      const stored = sessionStorage.getItem("fmc-booking");
      if (stored) {
        const b = JSON.parse(stored);
        if (b.serviceId) setServiceId(b.serviceId);
        if (b.selectedDate) {
          const d = new Date(b.selectedDate);
          setSelectedDate(d);
          setViewMonth(d.getMonth());
          setViewYear(d.getFullYear());
        }
        if (b.selectedSlot) setSelectedSlot(b.selectedSlot);
        if (b.details) setDetails(b.details);
      }
    } catch (e) { /* ignore */ }

    if (paid) {
      sessionStorage.removeItem("fmc-booking");
      setStep(5);
    } else {
      setStep(4);
      setPayError("Payment was cancelled. You can try again below.");
    }
    window.history.replaceState({}, "", window.location.pathname);
    setTimeout(() => {
      const el = document.getElementById("schedule");
      if (el) el.scrollIntoView({ behavior: "smooth", block: "start" });
    }, 60);
  }, []);

  const SERVICES = t.sch_services;
  const service = SERVICES.find(s => s.id === serviceId);

  const days = getMonthDays(viewYear, viewMonth);
  const isPast = (d) => {
    if (!d) return true;
    const date = new Date(viewYear, viewMonth, d);
    return date < new Date(today.getFullYear(), today.getMonth(), today.getDate());
  };
  const isToday = (d) => d === today.getDate() && viewMonth === today.getMonth() && viewYear === today.getFullYear();
  const isSelected = (d) => selectedDate && d === selectedDate.getDate() && viewMonth === selectedDate.getMonth() && viewYear === selectedDate.getFullYear();
  const hasSlots = (d) => {
    if (!d || isPast(d)) return false;
    const dow = new Date(viewYear, viewMonth, d).getDay();
    return dow !== 0;
  };

  const slotsFor = (date) => {
    if (!date) return [];
    const dow = date.getDay();
    if (dow === 0) return [];
    const base = ["8:00 AM","9:30 AM","11:00 AM","12:30 PM","2:00 PM","3:30 PM","5:00 PM"];
    const seed = date.getDate();
    return base.filter((_, i) => (seed + i) % 4 !== 0);
  };

  const goPrevMonth = () => {
    if (viewMonth === 0) { setViewMonth(11); setViewYear(y => y - 1); }
    else setViewMonth(m => m - 1);
  };
  const goNextMonth = () => {
    if (viewMonth === 11) { setViewMonth(0); setViewYear(y => y + 1); }
    else setViewMonth(m => m + 1);
  };

  const formattedDate = selectedDate
    ? `${t.dow_full[selectedDate.getDay()]}, ${t.months_short[selectedDate.getMonth()]} ${selectedDate.getDate()}`
    : "";

  const canProceedFromDetails = details.name && details.email && details.address;

  const submitPayment = async () => {
    setProcessing(true);
    setPayError(null);
    try {
      sessionStorage.setItem("fmc-booking", JSON.stringify({
        serviceId,
        selectedDate: selectedDate ? selectedDate.toISOString() : null,
        selectedSlot,
        details,
      }));
      const slotLabel = selectedDate && selectedSlot ? `${formattedDate} · ${selectedSlot}` : "";
      const res = await fetch("/api/create-checkout-session", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          serviceId,
          customerEmail: details.email,
          customerName: details.name,
          address: details.address,
          slotLabel,
          notes: details.notes,
        }),
      });
      if (!res.ok) {
        const err = await res.json().catch(() => ({}));
        throw new Error(err.error || `Checkout failed (${res.status})`);
      }
      const { url } = await res.json();
      if (!url) throw new Error("No checkout URL returned");
      window.location.href = url;
    } catch (e) {
      setProcessing(false);
      setPayError(e.message || "Something went wrong. Please try again.");
    }
  };

  const reset = () => {
    setStep(1);
    setSelectedDate(null);
    setSelectedSlot(null);
    setDetails({ name: "", email: "", phone: "", address: "", notes: "" });
    setCard({ number: "", exp: "", cvc: "", zip: "" });
  };

  const stepLabels = t.sch_steps;

  const payAmount = paymentModel === "full" ? service.price * 3 : paymentModel === "card" ? 0 : service.price;
  const payTitle = paymentModel === "deposit" ? t.sch_step4_deposit : paymentModel === "full" ? `${t.sch_step4_full} · $${service.price * 3}` : t.sch_step4_card;
  const payBlurb = paymentModel === "deposit" ? t.sch_step4_deposit_b : paymentModel === "full" ? t.sch_step4_full_b : t.sch_step4_card_b;
  const payCta = paymentModel === "card" ? t.sch_pay_card_save : `${t.nav_book.split(" ")[0]} $${payAmount} & ✓`;

  return (
    <section id="schedule" className="section" style={{ background: "var(--cream-2)", borderTop: "1px solid var(--line)" }}>
      <div className="container">
        <div className="scheduler-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 64, alignItems: "start" }}>
          <div className="sch-side" style={{ position: "sticky", top: 40 }}>
            <div className="font-mono" style={{ fontSize: 12, color: "var(--terracotta)", marginBottom: 16, letterSpacing: "0.1em" }}>
              {t.sch_eyebrow}
            </div>
            <h2 className="font-display sch-title" style={{ fontSize: 60, lineHeight: 0.95, letterSpacing: "-0.035em", margin: "0 0 24px", fontWeight: 600 }}>
              {t.sch_title_1}<br/>
              {t.sch_title_2} <span className="font-serif" style={{ color: "var(--terracotta)", fontWeight: 400 }}>{t.sch_title_word}</span>{t.sch_title_3}
            </h2>
            <p style={{ fontSize: 17, lineHeight: 1.55, color: "var(--muted)", margin: "0 0 32px", maxWidth: 440 }}>
              {t.sch_blurb}
            </p>

            <div style={{ display: "flex", flexDirection: "column", gap: 14, marginBottom: 32 }}>
              {[
                { icon: "🛡", title: t.sch_h_licensed, body: t.sch_h_licensed_b },
                { icon: "💰", title: t.sch_h_refund, body: t.sch_h_refund_b },
                { icon: "📍", title: t.sch_h_crew, body: t.sch_h_crew_b },
              ].map((h, i) => (
                <div key={i} style={{ display: "flex", gap: 14, alignItems: "start" }}>
                  <div style={{ width: 40, height: 40, borderRadius: 10, background: "var(--paper)", border: "1px solid var(--line-strong)", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 18, flexShrink: 0 }}>{h.icon}</div>
                  <div>
                    <div className="font-display" style={{ fontSize: 16, fontWeight: 600, marginBottom: 2 }}>{h.title}</div>
                    <div style={{ fontSize: 13, color: "var(--muted)", lineHeight: 1.45 }}>{h.body}</div>
                  </div>
                </div>
              ))}
            </div>

            <div className="card" style={{ padding: 18, display: "flex", gap: 14, alignItems: "center", background: "var(--paper)" }}>
              <div style={{ display: "flex" }}>
                {["RC","ML","JS"].map((init, i) => (
                  <div key={i} style={{ width: 40, height: 40, borderRadius: "50%", background: ["#C2552D","#7A8C6C","#C99A4A"][i], color: "var(--cream)", display: "flex", alignItems: "center", justifyContent: "center", fontFamily: "'Bricolage Grotesque', sans-serif", fontWeight: 600, fontSize: 13, marginLeft: i === 0 ? 0 : -10, border: "2px solid var(--paper)" }}>{init}</div>
                ))}
              </div>
              <div>
                <div className="font-display" style={{ fontSize: 14, fontWeight: 600 }}>{t.sch_crew_today}</div>
                <div className="font-mono" style={{ fontSize: 11, color: "var(--muted)" }}>{t.sch_crew_meta}</div>
              </div>
            </div>
          </div>

          <div className="card" style={{ background: "var(--paper)", padding: 0, overflow: "hidden", boxShadow: "0 30px 80px -30px rgba(42,31,24,0.25)" }}>
            <div className="sch-card-head sch-stepper" style={{ padding: "20px 22px", borderBottom: "1px solid var(--line)", display: "flex", alignItems: "center", gap: 6, minWidth: 0 }}>
              {stepLabels.map((label, i) => {
                const stepNum = i + 1;
                const active = step === stepNum;
                const done = step > stepNum;
                return (
                  <React.Fragment key={i}>
                    <div className="sch-step-row" style={{ display: "flex", alignItems: "center", gap: 6 }}>
                      <div style={{
                        width: 22, height: 22, borderRadius: "50%",
                        background: done ? "var(--sage)" : active ? "var(--terracotta)" : "transparent",
                        border: !done && !active ? "1.5px solid var(--line-strong)" : "none",
                        color: done || active ? "var(--cream)" : "var(--muted)",
                        display: "flex", alignItems: "center", justifyContent: "center",
                        fontFamily: "'Geist Mono', monospace", fontSize: 11, fontWeight: 600,
                        flexShrink: 0,
                      }}>
                        {done ? "✓" : stepNum}
                      </div>
                      <span className={"font-mono sch-step-label" + (active ? " active" : "")} style={{ fontSize: 11, color: active ? "var(--cocoa)" : "var(--muted)", fontWeight: active ? 600 : 400, whiteSpace: "nowrap" }}>{label}</span>
                    </div>
                    {i < stepLabels.length - 1 && <div className="sch-step-divider" style={{ flex: 1, height: 1, background: "var(--line)", minWidth: 12 }}/>}
                  </React.Fragment>
                );
              })}
            </div>

            <div className="sch-card-pad" style={{ padding: 28, minHeight: 540 }}>

              {step === 1 && (
                <div className="fade-up">
                  <h3 className="font-display" style={{ fontSize: 22, fontWeight: 600, margin: "0 0 6px" }}>{t.sch_step1_title}</h3>
                  <p style={{ fontSize: 14, color: "var(--muted)", margin: "0 0 24px" }}>{t.sch_step1_blurb}</p>
                  <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
                    {SERVICES.map(s => (
                      <button key={s.id} onClick={() => setServiceId(s.id)} style={{
                        textAlign: "left", padding: 18, borderRadius: 14,
                        border: serviceId === s.id ? "1.5px solid var(--terracotta)" : "1px solid var(--line-strong)",
                        background: serviceId === s.id ? "rgba(194,85,45,0.06)" : "transparent",
                        cursor: "pointer", transition: "all .15s ease",
                        display: "grid", gridTemplateColumns: "1fr auto", gap: 16, alignItems: "center"
                      }}>
                        <div>
                          <div className="font-display" style={{ fontSize: 16, fontWeight: 600, marginBottom: 4 }}>{s.name}</div>
                          <div style={{ fontSize: 13, color: "var(--muted)", marginBottom: 6 }}>{s.desc}</div>
                          <div className="font-mono" style={{ fontSize: 11, color: "var(--terracotta)" }}>{s.duration}</div>
                        </div>
                        <div style={{ textAlign: "right" }}>
                          <div className="font-display" style={{ fontSize: 22, fontWeight: 600 }}>${s.price}</div>
                          <div className="font-mono" style={{ fontSize: 10, color: "var(--muted)" }}>{t.sch_hold}</div>
                        </div>
                      </button>
                    ))}
                  </div>
                  <div style={{ display: "flex", justifyContent: "flex-end", marginTop: 28 }}>
                    <button className="btn btn-primary" onClick={() => setStep(2)}>{t.sch_continue}</button>
                  </div>
                </div>
              )}

              {step === 2 && (
                <div className="fade-up">
                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 6 }}>
                    <h3 className="font-display" style={{ fontSize: 22, fontWeight: 600, margin: 0 }}>{t.sch_step2_title}</h3>
                    <span className="font-mono" style={{ fontSize: 11, color: "var(--muted)" }}>{t.sch_step2_tz}</span>
                  </div>
                  <p style={{ fontSize: 14, color: "var(--muted)", margin: "0 0 20px" }}>
                    {service.name} · {service.duration}
                  </p>

                  <div className="scheduler-step2-grid" style={{ display: "grid", gridTemplateColumns: "1.1fr 0.9fr", gap: 24 }}>
                    <div>
                      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
                        <div className="font-display" style={{ fontSize: 16, fontWeight: 600 }}>{t.months[viewMonth]} {viewYear}</div>
                        <div style={{ display: "flex", gap: 4 }}>
                          <button onClick={goPrevMonth} style={{ width: 30, height: 30, borderRadius: 8, border: "1px solid var(--line-strong)", background: "transparent", cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center" }}>‹</button>
                          <button onClick={goNextMonth} style={{ width: 30, height: 30, borderRadius: 8, border: "1px solid var(--line-strong)", background: "transparent", cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center" }}>›</button>
                        </div>
                      </div>
                      <div style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", gap: 4, marginBottom: 8 }}>
                        {t.dow.map(d => (
                          <div key={d} className="font-mono" style={{ textAlign: "center", fontSize: 10, color: "var(--muted)", padding: "4px 0" }}>{d}</div>
                        ))}
                      </div>
                      <div style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", gap: 4 }}>
                        {days.map((d, i) => (
                          <div key={i}
                            onClick={() => {
                              if (d && !isPast(d) && hasSlots(d)) {
                                setSelectedDate(new Date(viewYear, viewMonth, d));
                                setSelectedSlot(null);
                              }
                            }}
                            className={`cal-day ${!d || isPast(d) || !hasSlots(d) ? "disabled" : ""} ${isToday(d) ? "today" : ""} ${isSelected(d) ? "selected" : ""}`}
                            style={{ position: "relative" }}
                          >
                            {d || ""}
                            {d && !isPast(d) && hasSlots(d) && !isSelected(d) && (
                              <span style={{ position: "absolute", bottom: 4, width: 4, height: 4, borderRadius: "50%", background: "var(--terracotta)" }}/>
                            )}
                          </div>
                        ))}
                      </div>
                      <div style={{ display: "flex", gap: 14, marginTop: 14, fontSize: 11, color: "var(--muted)" }} className="font-mono">
                        <span style={{ display: "flex", alignItems: "center", gap: 4 }}><span style={{ width: 4, height: 4, borderRadius: "50%", background: "var(--terracotta)" }}/> {t.sch_step2_legend_avail}</span>
                        <span style={{ display: "flex", alignItems: "center", gap: 4 }}>{t.sch_step2_legend_closed}</span>
                      </div>
                    </div>

                    <div>
                      <div className="font-display" style={{ fontSize: 16, fontWeight: 600, marginBottom: 14 }}>
                        {selectedDate ? formattedDate : t.sch_step2_pickdate}
                      </div>
                      {!selectedDate && (
                        <div style={{ padding: 32, border: "1px dashed var(--line-strong)", borderRadius: 12, textAlign: "center", color: "var(--muted)", fontSize: 13 }}>
                          {t.sch_step2_pickdate_hint}
                        </div>
                      )}
                      {selectedDate && (
                        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8, maxHeight: 320, overflowY: "auto" }}>
                          {slotsFor(selectedDate).map(s => (
                            <div key={s} className={`slot ${selectedSlot === s ? "selected" : ""}`} onClick={() => setSelectedSlot(s)}>{s}</div>
                          ))}
                        </div>
                      )}
                    </div>
                  </div>

                  <div style={{ display: "flex", justifyContent: "space-between", marginTop: 28 }}>
                    <button className="btn btn-ghost" onClick={() => setStep(1)}>{t.sch_back}</button>
                    <button className="btn btn-primary" disabled={!selectedDate || !selectedSlot} onClick={() => setStep(3)} style={{ opacity: !selectedDate || !selectedSlot ? 0.4 : 1, cursor: !selectedDate || !selectedSlot ? "not-allowed" : "pointer" }}>{t.sch_continue}</button>
                  </div>
                </div>
              )}

              {step === 3 && (
                <div className="fade-up">
                  <h3 className="font-display" style={{ fontSize: 22, fontWeight: 600, margin: "0 0 6px" }}>{t.sch_step3_title}</h3>
                  <p style={{ fontSize: 14, color: "var(--muted)", margin: "0 0 24px" }}>{t.sch_step3_blurb}</p>
                  <div className="sch-form-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}>
                    <div style={{ gridColumn: "1 / -1" }}>
                      <label className="font-mono" style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6, display: "block" }}>{t.sch_label_name}</label>
                      <input className="input" placeholder={t.sch_ph_name} value={details.name} onChange={e => setDetails({...details, name: e.target.value})}/>
                    </div>
                    <div>
                      <label className="font-mono" style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6, display: "block" }}>{t.sch_label_email}</label>
                      <input className="input" type="email" placeholder={t.sch_ph_email} value={details.email} onChange={e => setDetails({...details, email: e.target.value})}/>
                    </div>
                    <div>
                      <label className="font-mono" style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6, display: "block" }}>{t.sch_label_phone}</label>
                      <input className="input" placeholder={t.sch_ph_phone} value={details.phone} onChange={e => setDetails({...details, phone: e.target.value})}/>
                    </div>
                    <div style={{ gridColumn: "1 / -1" }}>
                      <label className="font-mono" style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6, display: "block" }}>{t.sch_label_address}</label>
                      <input className="input" placeholder={t.sch_ph_address} value={details.address} onChange={e => setDetails({...details, address: e.target.value})}/>
                    </div>
                    <div style={{ gridColumn: "1 / -1" }}>
                      <label className="font-mono" style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6, display: "block" }}>{t.sch_label_notes}</label>
                      <textarea className="input" rows={3} style={{ resize: "vertical", fontFamily: "inherit" }} placeholder={t.sch_ph_notes} value={details.notes} onChange={e => setDetails({...details, notes: e.target.value})}/>
                    </div>
                  </div>
                  <div style={{ display: "flex", justifyContent: "space-between", marginTop: 28 }}>
                    <button className="btn btn-ghost" onClick={() => setStep(2)}>{t.sch_back}</button>
                    <button className="btn btn-primary" disabled={!canProceedFromDetails} onClick={() => setStep(4)} style={{ opacity: !canProceedFromDetails ? 0.4 : 1, cursor: !canProceedFromDetails ? "not-allowed" : "pointer" }}>{t.sch_continue_pay}</button>
                  </div>
                </div>
              )}

              {step === 4 && (
                <div className="fade-up">
                  <h3 className="font-display" style={{ fontSize: 22, fontWeight: 600, margin: "0 0 6px" }}>
                    {payTitle}
                  </h3>
                  <p style={{ fontSize: 14, color: "var(--muted)", margin: "0 0 24px" }}>
                    {payBlurb}
                  </p>

                  <div style={{ padding: 18, background: "var(--cream-2)", borderRadius: 12, marginBottom: 20 }}>
                    <div style={{ display: "flex", justifyContent: "space-between", fontSize: 14, marginBottom: 8 }}>
                      <span>{service.name}</span>
                      <span className="font-mono">${service.price}.00</span>
                    </div>
                    <div style={{ display: "flex", justifyContent: "space-between", fontSize: 13, color: "var(--muted)", marginBottom: 12 }}>
                      <span>{formattedDate} · {selectedSlot}</span>
                      <span></span>
                    </div>
                    <div style={{ height: 1, background: "var(--line)", marginBottom: 12 }}/>
                    <div style={{ display: "flex", justifyContent: "space-between", fontSize: 16, fontWeight: 600 }}>
                      <span>{t.sch_total_today}</span>
                      <span className="font-display">${payAmount}.00</span>
                    </div>
                  </div>

                  <div style={{ padding: "16px 18px", border: "1px dashed var(--line-strong)", borderRadius: 12, fontSize: 13, color: "var(--cocoa)", background: "var(--paper)", lineHeight: 1.5 }}>
                    You'll complete payment securely on Stripe. We authorize <strong>${payAmount}.00</strong> on your card as a hold — nothing is charged until your visit is complete.
                  </div>

                  {payError && (
                    <div style={{ marginTop: 14, padding: "12px 14px", background: "rgba(196,80,60,0.08)", border: "1px solid rgba(196,80,60,0.3)", borderRadius: 10, color: "var(--terracotta)", fontSize: 13 }}>
                      {payError}
                    </div>
                  )}

                  <div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 18, fontSize: 12, color: "var(--muted)" }}>
                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/></svg>
                    <span>{t.sch_secured}</span>
                  </div>

                  <div style={{ display: "flex", justifyContent: "space-between", marginTop: 28 }}>
                    <button className="btn btn-ghost" onClick={() => setStep(3)} disabled={processing}>{t.sch_back}</button>
                    <button className="btn btn-primary" onClick={submitPayment} disabled={processing} style={{ minWidth: 200, justifyContent: "center" }}>
                      {processing ? (
                        <>
                          <svg className="spin" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3"><circle cx="12" cy="12" r="9" strokeDasharray="40 20"/></svg>
                          {t.sch_processing}
                        </>
                      ) : payCta}
                    </button>
                  </div>
                </div>
              )}

              {step === 5 && (
                <div className="fade-up" style={{ textAlign: "center", padding: "20px 0" }}>
                  <div style={{ width: 72, height: 72, borderRadius: "50%", background: "rgba(122,140,108,0.15)", color: "var(--sage)", display: "flex", alignItems: "center", justifyContent: "center", margin: "0 auto 20px" }}>
                    <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
                      <path d="M5 13l4 4L19 7"/>
                    </svg>
                  </div>
                  <h3 className="font-display" style={{ fontSize: 32, fontWeight: 600, margin: "0 0 10px", letterSpacing: "-0.02em" }}>
                    {t.sch_step5_title_pre}{details.name.split(" ")[0] || t.sch_step5_title_default}.
                  </h3>
                  <p style={{ fontSize: 16, color: "var(--muted)", margin: "0 0 32px", maxWidth: 420, marginLeft: "auto", marginRight: "auto", lineHeight: 1.5 }}>
                    {t.sch_step5_blurb_pre} <strong>{details.email}</strong>{t.sch_step5_blurb_post}
                  </p>

                  <div style={{ display: "inline-block", textAlign: "left", padding: 20, background: "var(--cream-2)", borderRadius: 14, marginBottom: 24, minWidth: 320 }}>
                    <div className="font-mono" style={{ fontSize: 10, color: "var(--muted)", marginBottom: 8 }}>{t.sch_booking} #FMC-{Math.floor(Math.random() * 90000) + 10000}</div>
                    <div className="font-display" style={{ fontSize: 18, fontWeight: 600, marginBottom: 12 }}>{service.name}</div>
                    <div style={{ display: "grid", gridTemplateColumns: "auto 1fr", gap: "6px 14px", fontSize: 13 }}>
                      <span className="font-mono" style={{ color: "var(--muted)" }}>{t.sch_when}</span>
                      <span>{formattedDate} · {selectedSlot}</span>
                      <span className="font-mono" style={{ color: "var(--muted)" }}>{t.sch_where}</span>
                      <span>{details.address}</span>
                      <span className="font-mono" style={{ color: "var(--muted)" }}>{t.sch_crew}</span>
                      <span>{t.sch_crew_assigned}</span>
                      <span className="font-mono" style={{ color: "var(--muted)" }}>{t.sch_paid}</span>
                      <span style={{ color: "var(--sage)", fontWeight: 600 }}>${payAmount}.00</span>
                    </div>
                  </div>

                  <div style={{ display: "flex", gap: 10, justifyContent: "center" }}>
                    <button className="btn btn-ghost" onClick={reset}>{t.sch_book_another}</button>
                    <a href="#" className="btn btn-primary">{t.sch_add_cal}</a>
                  </div>
                </div>
              )}

            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

window.Scheduler = Scheduler;
