/* global React, Icon, fmtMoney, initials, productById, formatDate, StatusBadge, CartSummary, SidePanel */
const { useState: uS5, useEffect: uE5, useRef: uR5 } = React;

// ===== STEP C: PAY (multi-prescription summary + Stripe-style card) =====
function PayScreen({ allocations, patients, setRoute, processPayment, basket }) {
  const [tab, setTab] = uS5("saved");
  const [card, setCard] = uS5({ number: "", exp: "", cvc: "", postcode: "" });
  const [name, setName] = uS5("Beaumont Aesthetics Ltd");
  const [processing, setProcessing] = uS5(false);

  const subtotal = allocations.reduce((s, a) => s + a.items.reduce((ss, it) => ss + productById(it.pid).price * it.qty, 0), 0);
  const shipping = allocations.length * 4.95;
  const total = subtotal + shipping;

  const formatCard = (v) => v.replace(/\D/g, "").slice(0, 16).replace(/(\d{4})(?=\d)/g, "$1 ");
  const formatExp = (v) => {
    const d = v.replace(/\D/g, "").slice(0, 4);
    return d.length > 2 ? d.slice(0, 2) + " / " + d.slice(2) : d;
  };

  const submit = (e) => {
    e.preventDefault();
    setProcessing(true);
    setTimeout(() => {
      const rxIds = processPayment();
      setProcessing(false);
      setRoute({ name: "sign-queue", rxIds });
    }, 1200);
  };

  return (
    <div className="page">
      <div className="page-header">
        <div>
          <div className="page-eyebrow">Step 4 of 5 · Payment</div>
          <h1 className="page-title">Pay & generate prescriptions</h1>
          <p className="page-sub">Once paid, a prescription will be created for each patient and queued for your e-signature.</p>
        </div>
      </div>

      <div className="stepper">
        <div className="step done"><div className="step-num"><Icon.Check /></div>Basket</div>
        <div className="step-divider" />
        <div className="step done"><div className="step-num"><Icon.Check /></div>Allocate</div>
        <div className="step-divider" />
        <div className="step done"><div className="step-num"><Icon.Check /></div>Declare</div>
        <div className="step-divider" />
        <div className="step active"><div className="step-num">4</div>Pay</div>
        <div className="step-divider" />
        <div className="step"><div className="step-num">5</div>Sign</div>
      </div>

      <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 16 }}>
        <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
          <div className="card">
            <div className="section-h"><h2>Prescriptions ({allocations.length})</h2></div>
            {allocations.map((a, i) => {
              const p = patients.find(p => p.id === a.patientId);
              const aTotal = a.items.reduce((s, it) => s + productById(it.pid).price * it.qty, 0);
              return (
                <div key={i} style={{ padding: "14px 0", borderTop: i > 0 ? "1px solid var(--line)" : "none", display: "flex", gap: 14, alignItems: "center" }}>
                  <div className="patient-avatar" style={{ width: 36, height: 36 }}>{initials(p.first, p.last)}</div>
                  <div style={{ flex: 1 }}>
                    <div style={{ fontWeight: 500 }}>{p.first} {p.last}</div>
                    <div style={{ fontSize: 11, color: "var(--ink-4)" }}>{a.items.map(it => `${productById(it.pid).strength} ×${it.qty}`).join(", ")}</div>
                  </div>
                  <div className="tnum" style={{ fontFamily: "'Newsreader', serif", fontSize: 18 }}>{fmtMoney(aTotal)}</div>
                </div>
              );
            })}
          </div>

          <form className="pay-card" onSubmit={submit}>
            <div className="pay-tabs">
              <button type="button" className={"pay-tab" + (tab === "saved" ? " active" : "")} onClick={() => setTab("saved")}>Saved card</button>
              <button type="button" className={"pay-tab" + (tab === "card" ? " active" : "")} onClick={() => setTab("card")}>New card</button>
            </div>
            <div className="pay-body">
              {tab === "saved" ? (
                <div style={{ border: "1px solid var(--accent)", boxShadow: "0 0 0 1px var(--accent)", borderRadius: 10, padding: 16, display: "flex", alignItems: "center", gap: 14, background: "var(--accent-soft)" }}>
                  <div style={{ width: 38, height: 24, borderRadius: 4, background: "#1A1F71", color: "#fff", display: "grid", placeItems: "center", fontSize: 9, fontWeight: 700 }}>VISA</div>
                  <div style={{ flex: 1 }}>
                    <div style={{ fontWeight: 500, fontSize: 13 }}>Visa ending 4242</div>
                    <div style={{ fontSize: 11, color: "var(--ink-3)" }}>Beaumont Aesthetics Ltd · Expires 09/29</div>
                  </div>
                  <Icon.Check style={{ color: "var(--accent)" }} />
                </div>
              ) : (
                <>
                  <div className="field" style={{ marginBottom: 14 }}>
                    <label>Cardholder name</label>
                    <input className="input" value={name} onChange={(e) => setName(e.target.value)} />
                  </div>
                  <div className="field" style={{ marginBottom: 14 }}>
                    <label>Card information</label>
                    <div className="card-input">
                      <div className="card-input-row">
                        <input placeholder="1234 1234 1234 1234" value={card.number} onChange={(e) => setCard({ ...card, number: formatCard(e.target.value) })} />
                        <div className="card-brands">
                          <div className="card-brand" style={{ background: "#1A1F71" }}>VISA</div>
                          <div className="card-brand" style={{ background: "#EB001B" }}>MC</div>
                        </div>
                      </div>
                      <div className="card-input-grid">
                        <div><input placeholder="MM / YY" value={card.exp} onChange={(e) => setCard({ ...card, exp: formatExp(e.target.value) })} /></div>
                        <div><input placeholder="CVC" value={card.cvc} onChange={(e) => setCard({ ...card, cvc: e.target.value.replace(/\D/g, "").slice(0,4) })} /></div>
                      </div>
                    </div>
                  </div>
                </>
              )}
            </div>
          </form>
        </div>

        <div style={{ position: "sticky", top: 88, alignSelf: "start" }}>
          <div className="card">
            <div className="section-h"><h2>Total</h2></div>
            <div className="summary-line"><span>Subtotal · {allocations.length} prescription{allocations.length > 1 ? "s" : ""}</span><span className="v tnum">{fmtMoney(subtotal)}</span></div>
            <div className="summary-line"><span>Tracked delivery × {allocations.length}</span><span className="v tnum">{fmtMoney(shipping)}</span></div>
            <div className="summary-line"><span>VAT</span><span className="v muted">included</span></div>
            <div className="summary-line total"><span>To pay</span><span className="v tnum">{fmtMoney(total)}</span></div>
            <button className="btn btn-accent btn-lg" onClick={submit} disabled={processing} style={{ width: "100%", justifyContent: "center", marginTop: 14 }}>
              {processing ? "Processing…" : <><Icon.Lock /> Pay {fmtMoney(total)}</>}
            </button>
            <div style={{ marginTop: 10, fontSize: 11, color: "var(--ink-4)", textAlign: "center" }}>
              Prescriptions await your e-signature before dispatch.
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

// ===== STEP D: SIGN QUEUE — list of unsigned Rx after payment =====
function SignQueueScreen({ rxIds, prescriptions, patients, setRoute, openSign }) {
  const queued = prescriptions.filter(rx => rxIds.includes(rx.id));
  const allSigned = queued.every(rx => rx.status === "signed");

  return (
    <div className="page" style={{ maxWidth: 880, marginInline: "auto" }}>
      <div className="page-header">
        <div>
          <div className="page-eyebrow">Step 5 of 5 · E-signature</div>
          <h1 className="page-title">{allSigned ? "All prescriptions signed." : "Sign your prescriptions"}</h1>
          <p className="page-sub">{allSigned ? "Pharmacist will dispense and dispatch within 2 working hours." : "Each prescription needs your e-signature before the pharmacist will dispense it."}</p>
        </div>
      </div>

      <div className="stepper">
        <div className="step done"><div className="step-num"><Icon.Check /></div>Basket</div>
        <div className="step-divider" />
        <div className="step done"><div className="step-num"><Icon.Check /></div>Allocate</div>
        <div className="step-divider" />
        <div className="step done"><div className="step-num"><Icon.Check /></div>Declare</div>
        <div className="step-divider" />
        <div className="step done"><div className="step-num"><Icon.Check /></div>Pay</div>
        <div className="step-divider" />
        <div className={"step" + (allSigned ? " done" : " active")}><div className="step-num">{allSigned ? <Icon.Check /> : "5"}</div>Sign</div>
      </div>

      <div className="tbl-card">
        <table className="tbl">
          <thead><tr><th>Rx ID</th><th>Patient</th><th>Items</th><th>Status</th><th></th></tr></thead>
          <tbody>
            {queued.map(rx => {
              const p = patients.find(p => p.id === rx.patientId);
              return (
                <tr key={rx.id}>
                  <td className="tnum"><strong>{rx.id}</strong></td>
                  <td>
                    <div className="patient-cell">
                      <div className="patient-avatar">{initials(p.first, p.last)}</div>
                      <div className="patient-name">{p.first} {p.last}</div>
                    </div>
                  </td>
                  <td>{rx.items.map(it => `${productById(it.pid).strength} ×${it.qty}`).join(", ")}</td>
                  <td><StatusBadge status={rx.status === "signed" ? "paid" : "review"} /></td>
                  <td className="right">
                    {rx.status === "signed" ? (
                      <span className="muted" style={{ fontSize: 12 }}>Signed {formatDate(rx.signedAt)}</span>
                    ) : (
                      <button className="btn btn-accent btn-sm" onClick={() => openSign(rx.id)}>Verify & sign <Icon.ChevronR /></button>
                    )}
                  </td>
                </tr>
              );
            })}
          </tbody>
        </table>
      </div>

      <div style={{ display: "flex", justifyContent: "space-between", marginTop: 24 }}>
        <button className="btn btn-ghost" onClick={() => setRoute("dashboard")}>Sign later from dashboard</button>
        {allSigned && <button className="btn btn-primary" onClick={() => setRoute("dashboard")}>Done <Icon.Check /></button>}
      </div>
    </div>
  );
}

// ===== Prescriptions screen (always available from sidebar) =====
function PrescriptionsScreen({ prescriptions, patients, setRoute, openSign }) {
  const [tab, setTab] = uS5("unsigned");
  const filtered = prescriptions.filter(rx => tab === "unsigned" ? rx.status !== "signed" : rx.status === "signed");
  const unsignedCount = prescriptions.filter(rx => rx.status !== "signed").length;

  return (
    <div className="page">
      <div className="page-header">
        <div>
          <div className="page-eyebrow">Clinical sign-off</div>
          <h1 className="page-title">Prescriptions</h1>
          <p className="page-sub">{unsignedCount > 0 ? `${unsignedCount} prescription${unsignedCount > 1 ? "s" : ""} awaiting your signature.` : "All prescriptions signed and dispatched."}</p>
        </div>
        <div className="page-actions">
          <button className="btn btn-accent" onClick={() => setRoute("basket")}><Icon.New /> New prescription</button>
        </div>
      </div>

      <div style={{ display: "flex", gap: 4, padding: 4, background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 8, width: "fit-content", marginBottom: 16 }}>
        <button className="btn btn-sm" style={{ background: tab === "unsigned" ? "var(--ink)" : "transparent", color: tab === "unsigned" ? "#fff" : "var(--ink-3)", border: "none" }} onClick={() => setTab("unsigned")}>
          Unsigned {unsignedCount > 0 && <span className="badge" style={{ background: "var(--rust)", color: "#fff", marginLeft: 4 }}>{unsignedCount}</span>}
        </button>
        <button className="btn btn-sm" style={{ background: tab === "signed" ? "var(--ink)" : "transparent", color: tab === "signed" ? "#fff" : "var(--ink-3)", border: "none" }} onClick={() => setTab("signed")}>Signed</button>
      </div>

      <div className="tbl-card">
        <table className="tbl">
          <thead><tr><th>Rx ID</th><th>Created</th><th>Patient</th><th>Items</th><th>Total</th><th>Status</th><th></th></tr></thead>
          <tbody>
            {filtered.map(rx => {
              const p = patients.find(p => p.id === rx.patientId);
              return (
                <tr key={rx.id}>
                  <td className="tnum"><strong>{rx.id}</strong></td>
                  <td>{formatDate(rx.date)}</td>
                  <td>
                    <div className="patient-cell">
                      <div className="patient-avatar">{initials(p.first, p.last)}</div>
                      <div>
                        <div className="patient-name">{p.first} {p.last}</div>
                        <div className="patient-meta">DOB {formatDate(p.dob)}</div>
                      </div>
                    </div>
                  </td>
                  <td>{rx.items.map(it => `${productById(it.pid).strength} ×${it.qty}`).join(", ")}</td>
                  <td className="tnum"><strong>{fmtMoney(rx.total)}</strong></td>
                  <td>
                    {rx.status === "signed"
                      ? <span className="badge badge-paid"><span className="badge-dot" />Signed</span>
                      : <span className="badge badge-pending"><span className="badge-dot" />Unsigned</span>}
                  </td>
                  <td className="right">
                    {rx.status === "signed"
                      ? <button className="btn btn-link" onClick={() => openSign(rx.id)}>View</button>
                      : <button className="btn btn-accent btn-sm" onClick={() => openSign(rx.id)}>Verify & sign <Icon.ChevronR /></button>}
                  </td>
                </tr>
              );
            })}
          </tbody>
        </table>
        {filtered.length === 0 && (
          <div style={{ padding: 60, textAlign: "center", color: "var(--ink-3)" }}>
            {tab === "unsigned" ? "No prescriptions awaiting signature. Nicely done." : "No signed prescriptions yet."}
          </div>
        )}
      </div>
    </div>
  );
}

// ===== E-SIGNATURE MODAL =====
function SignModal({ rx, patient, onClose, onSign }) {
  const [phase, setPhase] = uS5("review"); // review | sign | email-verify | done
  const [directions, setDirections] = uS5("Inject once weekly subcutaneously, on the same day each week. Rotate injection sites.");
  const [check1, setCheck1] = uS5(false);
  const [check2, setCheck2] = uS5(false);
  const [signed, setSigned] = uS5(false);
  const canvasRef = uR5(null);
  const [drawing, setDrawing] = uS5(false);

  // Signature pad
  uE5(() => {
    if (phase !== "sign") return;
    const c = canvasRef.current;
    if (!c) return;
    const ctx = c.getContext("2d");
    ctx.lineWidth = 2.2;
    ctx.lineCap = "round";
    ctx.strokeStyle = "#0B1F2A";
    ctx.fillStyle = "#fff";
    ctx.fillRect(0, 0, c.width, c.height);
  }, [phase]);

  const sigEvents = {
    onMouseDown: (e) => {
      const c = canvasRef.current;
      const r = c.getBoundingClientRect();
      const ctx = c.getContext("2d");
      ctx.beginPath();
      ctx.moveTo(e.clientX - r.left, e.clientY - r.top);
      setDrawing(true);
      setSigned(true);
    },
    onMouseMove: (e) => {
      if (!drawing) return;
      const c = canvasRef.current;
      const r = c.getBoundingClientRect();
      const ctx = c.getContext("2d");
      ctx.lineTo(e.clientX - r.left, e.clientY - r.top);
      ctx.stroke();
    },
    onMouseUp: () => setDrawing(false),
    onMouseLeave: () => setDrawing(false),
  };

  const clearSig = () => {
    const c = canvasRef.current;
    const ctx = c.getContext("2d");
    ctx.fillStyle = "#fff";
    ctx.fillRect(0, 0, c.width, c.height);
    setSigned(false);
  };

  return (
    <div className="modal-backdrop" onClick={onClose}>
      <div className="card" style={{ width: 640, maxHeight: "92vh", overflow: "auto", padding: 0 }} onClick={(e) => e.stopPropagation()}>
        {phase === "review" && (
          <>
            <div style={{ padding: "20px 24px", borderBottom: "1px solid var(--line)", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
              <div>
                <div className="muted" style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.1em" }}>Verify prescription</div>
                <div className="serif tnum" style={{ fontSize: 22, letterSpacing: "-0.02em", marginTop: 2 }}>{rx.id}</div>
              </div>
              <button className="icon-btn" onClick={onClose}><Icon.Close /></button>
            </div>
            <div style={{ padding: "20px 24px" }}>
              <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, padding: 16, background: "var(--canvas-2)", borderRadius: 10, marginBottom: 18, fontSize: 13 }}>
                <div>
                  <div className="muted" style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.1em", marginBottom: 4 }}>Patient</div>
                  <div style={{ fontWeight: 600 }}>{patient.first} {patient.last}</div>
                  <div className="muted" style={{ marginTop: 2 }}>DOB {formatDate(patient.dob)} · BMI {typeof patient.bmi === "number" ? patient.bmi.toFixed(1) : patient.bmi}</div>
                </div>
                <div>
                  <div className="muted" style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.1em", marginBottom: 4 }}>Delivery</div>
                  <div>{patient.address || "—"}</div>
                  <div className="muted">{patient.postcode || ""}</div>
                </div>
              </div>

              <div style={{ marginBottom: 18 }}>
                <div className="muted" style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.1em", marginBottom: 6 }}>Items</div>
                {rx.items.map(it => {
                  const p = productById(it.pid);
                  return (
                    <div key={it.pid} className="order-line" style={{ paddingTop: 8, paddingBottom: 8 }}>
                      <div className="order-line-img" style={{ width: 48, height: 48 }}>{p.img && <img src={p.img} alt={p.strength} />}</div>
                      <div className="order-line-body">
                        <div className="order-line-title">{p.name} {p.strength}</div>
                        <div className="order-line-sub">qty {it.qty} · 4 doses each</div>
                      </div>
                      <div className="order-line-price tnum">{fmtMoney(p.price * it.qty)}</div>
                    </div>
                  );
                })}
              </div>

              <div className="field" style={{ marginBottom: 18 }}>
                <label>Directions to patient</label>
                <textarea className="textarea" rows={3} value={directions} onChange={(e) => setDirections(e.target.value)} />
              </div>

              <div style={{ display: "flex", flexDirection: "column", gap: 10, padding: 16, background: "var(--canvas-2)", borderRadius: 10, fontSize: 12, lineHeight: 1.5 }}>
                <label style={{ display: "flex", gap: 10, alignItems: "flex-start", cursor: "pointer" }}>
                  <input type="checkbox" checked={check1} onChange={(e) => setCheck1(e.target.checked)} style={{ marginTop: 2 }} />
                  <span>I confirm I have <strong>clinically assessed this patient</strong> and the prescription is appropriate, safe, and consistent with current GLP-1 prescribing guidance.</span>
                </label>
                <label style={{ display: "flex", gap: 10, alignItems: "flex-start", cursor: "pointer" }}>
                  <input type="checkbox" checked={check2} onChange={(e) => setCheck2(e.target.checked)} style={{ marginTop: 2 }} />
                  <span>I confirm the patient details, drug, strength, quantity and directions above are <strong>accurate</strong>, and I accept clinical responsibility as the prescriber.</span>
                </label>
              </div>
            </div>
            <div style={{ padding: "16px 24px", borderTop: "1px solid var(--line)", display: "flex", justifyContent: "space-between", gap: 8 }}>
              <button className="btn btn-ghost" onClick={onClose}>Cancel</button>
              <button className="btn btn-accent" disabled={!check1 || !check2} onClick={() => setPhase("sign")}>
                Continue to signature <Icon.ChevronR />
              </button>
            </div>
          </>
        )}

        {phase === "sign" && (
          <>
            <div style={{ padding: "20px 24px", borderBottom: "1px solid var(--line)", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
              <div>
                <div className="muted" style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.1em" }}>Step 2 · Signature</div>
                <div className="serif" style={{ fontSize: 22, letterSpacing: "-0.02em", marginTop: 2 }}>Sign with your name</div>
              </div>
              <button className="icon-btn" onClick={onClose}><Icon.Close /></button>
            </div>
            <div style={{ padding: "20px 24px" }}>
              <div style={{ fontSize: 13, color: "var(--ink-3)", marginBottom: 14, lineHeight: 1.55 }}>
                Sign in the box below using your mouse or trackpad. This signature is appended to the prescription record alongside your prescriber number.
              </div>
              <div style={{ border: "1.5px dashed var(--line-2)", borderRadius: 10, background: "#fff", padding: 8 }}>
                <canvas ref={canvasRef} width={560} height={180} style={{ display: "block", cursor: "crosshair", borderRadius: 6 }} {...sigEvents} />
                <div style={{ display: "flex", justifyContent: "space-between", padding: "8px 6px 4px" }}>
                  <div style={{ fontSize: 11, color: "var(--ink-4)" }}>Dr. John Smith · GPhC 2087443 · {formatDate(new Date().toISOString().slice(0,10))}</div>
                  <button className="btn btn-link" onClick={clearSig} style={{ fontSize: 11 }}>Clear</button>
                </div>
              </div>
            </div>
            <div style={{ padding: "16px 24px", borderTop: "1px solid var(--line)", display: "flex", justifyContent: "space-between", gap: 8 }}>
              <button className="btn btn-ghost" onClick={() => setPhase("review")}>← Back</button>
              <button className="btn btn-accent" disabled={!signed} onClick={() => setPhase("email-verify")}>
                Send verification email <Icon.ChevronR />
              </button>
            </div>
          </>
        )}

        {phase === "email-verify" && (
          <>
            <div style={{ padding: "20px 24px", borderBottom: "1px solid var(--line)", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
              <div>
                <div className="muted" style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.1em" }}>Step 3 · Verify</div>
                <div className="serif" style={{ fontSize: 22, letterSpacing: "-0.02em", marginTop: 2 }}>Confirm by email</div>
              </div>
              <button className="icon-btn" onClick={onClose}><Icon.Close /></button>
            </div>
            <div style={{ padding: "32px 24px", textAlign: "center" }}>
              <div style={{ width: 64, height: 64, borderRadius: "50%", background: "var(--accent-soft)", color: "var(--accent)", display: "grid", placeItems: "center", margin: "0 auto 18px" }}>
                <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/></svg>
              </div>
              <div style={{ fontFamily: "'Newsreader', serif", fontSize: 22, letterSpacing: "-0.02em", marginBottom: 8 }}>Verification link sent</div>
              <div style={{ fontSize: 13, color: "var(--ink-3)", maxWidth: 380, margin: "0 auto 22px", lineHeight: 1.55 }}>
                We've sent a one-time verification link to <strong>j.smith@beaumontaesthetics.co.uk</strong>. Click the link to finalise this prescription. The link expires in 15 minutes.
              </div>
              <div style={{ fontSize: 11, color: "var(--ink-4)", marginBottom: 14 }}>For demo purposes:</div>
              <button className="btn btn-accent btn-lg" onClick={() => { onSign(rx.id); setPhase("done"); }}>
                <Icon.Check /> Simulate clicking the link
              </button>
            </div>
            <div style={{ padding: "16px 24px", borderTop: "1px solid var(--line)", display: "flex", justifyContent: "space-between" }}>
              <button className="btn btn-ghost" onClick={() => setPhase("sign")}>← Back</button>
              <button className="btn btn-link">Resend email</button>
            </div>
          </>
        )}

        {phase === "done" && (
          <div style={{ padding: "40px 24px", textAlign: "center" }}>
            <div style={{ width: 64, height: 64, borderRadius: "50%", background: "var(--green-soft)", color: "var(--green)", display: "grid", placeItems: "center", margin: "0 auto 18px" }}>
              <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6L9 17l-5-5"/></svg>
            </div>
            <div style={{ fontFamily: "'Newsreader', serif", fontSize: 26, letterSpacing: "-0.02em", marginBottom: 8 }}>Prescription signed</div>
            <div style={{ fontSize: 13, color: "var(--ink-3)", maxWidth: 380, margin: "0 auto 22px", lineHeight: 1.55 }}>
              {rx.id} has been released to the dispensing pharmacist. Tracked dispatch usually completes within 1 working day.
            </div>
            <button className="btn btn-primary" onClick={onClose}>Done</button>
          </div>
        )}
      </div>
    </div>
  );
}

window.PayScreen = PayScreen;
window.SignQueueScreen = SignQueueScreen;
window.PrescriptionsScreen = PrescriptionsScreen;
window.SignModal = SignModal;
