{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "consent-form",
  "title": "Consent form with signature",
  "description": "Scroll-to-read consent document with a reading progress meter that unlocks the required statements, typed legal name, a draw-to-sign canvas with clear, validation and a signed-and-sealed state with a downloadable copy.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/button.json",
    "https://goodui.dev/r/checkbox.json",
    "https://goodui.dev/r/input.json",
    "https://goodui.dev/r/success-check.json"
  ],
  "files": [
    {
      "path": "registry/blocks/booking/consent-form.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Check, Download, Eraser, FileSignature, Lock, PenLine, ShieldCheck } from \"lucide-react\"\nimport { Button } from \"@/components/goodui/button\"\nimport { Checkbox } from \"@/components/goodui/checkbox\"\nimport { Input } from \"@/components/goodui/input\"\nimport { SuccessCheck } from \"@/components/goodui/success-check\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Demo data ---------- */\n\nconst SECTIONS = [\n  { title: \"What the treatment involves\", body: \"Chemical color services use oxidative dyes and developers that lift and deposit pigment. Results depend on hair history, porosity and previous products, so the final shade can vary from the inspiration photo. A strand test may be recommended for lightening services.\" },\n  { title: \"Risks and side effects\", body: \"Scalp irritation, redness, itching or, rarely, an allergic reaction can occur. Lightening can cause dryness or breakage, especially on previously treated hair. Tell your stylist about any reaction you have ever had to hair products or henna.\" },\n  { title: \"Patch testing\", body: \"A patch test 48 hours before any color service is required for new clients and after any change in health or medication. Declining a patch test means the service may be refused on the day.\" },\n  { title: \"Aftercare and results\", body: \"Use the recommended sulfate-free products and avoid washing for 48 hours. Color may fade faster with heat styling, swimming or sun exposure. Corrections requested within 7 days are complimentary when aftercare was followed.\" },\n  { title: \"Photos and privacy\", body: \"With your permission we may photograph your hair for your client file and our portfolio. Your health details are stored securely, never shared, and deleted on request.\" },\n]\nconst CLAUSES = [\n  { id: \"read\", label: \"I have read and understood the information above\", required: true },\n  { id: \"health\", label: \"I have disclosed all allergies, medications and previous reactions\", required: true },\n  { id: \"risks\", label: \"I accept the risks described and consent to the treatment\", required: true },\n  { id: \"photos\", label: \"You may use photos of my hair in your portfolio (optional)\", required: false },\n]\n\n/* ---------- Block ---------- */\n\nexport default function ConsentForm() {\n  const scrollRef = React.useRef<HTMLDivElement>(null)\n  const canvasRef = React.useRef<HTMLCanvasElement>(null)\n  const drawing = React.useRef(false)\n  const [progress, setProgress] = React.useState(0)\n  const [agreed, setAgreed] = React.useState<string[]>([])\n  const [name, setName] = React.useState(\"\")\n  const [hasInk, setHasInk] = React.useState(false)\n  const [error, setError] = React.useState<string | null>(null)\n  const [signed, setSigned] = React.useState<{ at: string } | null>(null)\n  const [submitting, setSubmitting] = React.useState(false)\n\n  const readAll = progress >= 0.98\n  const requiredOk = CLAUSES.filter((c) => c.required).every((c) => agreed.includes(c.id))\n\n  const onScroll = () => {\n    const el = scrollRef.current\n    if (!el) return\n    const max = el.scrollHeight - el.clientHeight\n    setProgress(max <= 0 ? 1 : Math.min(1, el.scrollTop / max))\n  }\n  React.useEffect(onScroll, [])\n\n  // Signature pad\n  const pos = (e: React.PointerEvent<HTMLCanvasElement>) => {\n    const c = canvasRef.current!\n    const r = c.getBoundingClientRect()\n    return { x: ((e.clientX - r.left) / r.width) * c.width, y: ((e.clientY - r.top) / r.height) * c.height }\n  }\n  const start = (e: React.PointerEvent<HTMLCanvasElement>) => {\n    if (signed) return\n    drawing.current = true\n    const ctx = canvasRef.current!.getContext(\"2d\")!\n    const p = pos(e)\n    ctx.beginPath()\n    ctx.moveTo(p.x, p.y)\n    e.currentTarget.setPointerCapture(e.pointerId)\n  }\n  const move = (e: React.PointerEvent<HTMLCanvasElement>) => {\n    if (!drawing.current) return\n    const ctx = canvasRef.current!.getContext(\"2d\")!\n    const p = pos(e)\n    ctx.lineWidth = 2.4\n    ctx.lineCap = \"round\"\n    ctx.lineJoin = \"round\"\n    ctx.strokeStyle = getComputedStyle(canvasRef.current!).color\n    ctx.lineTo(p.x, p.y)\n    ctx.stroke()\n    setHasInk(true)\n  }\n  const end = () => {\n    drawing.current = false\n  }\n  const clear = () => {\n    const c = canvasRef.current\n    c?.getContext(\"2d\")?.clearRect(0, 0, c.width, c.height)\n    setHasInk(false)\n  }\n  const sign = async () => {\n    if (!readAll) return setError(\"Please scroll through the whole document first.\")\n    if (!requiredOk) return setError(\"Tick the three required statements.\")\n    if (name.trim().length < 3) return setError(\"Type your full name.\")\n    if (!hasInk) return setError(\"Draw your signature in the box.\")\n    setError(null)\n    setSubmitting(true)\n    await new Promise((r) => setTimeout(r, 900))\n    setSubmitting(false)\n    setSigned({ at: new Date().toLocaleString(\"en-US\", { dateStyle: \"medium\", timeStyle: \"short\" }) })\n  }\n  const download = () => {\n    const sig = canvasRef.current?.toDataURL(\"image/png\") ?? \"\"\n    const html = `<div style=\"font-family:system-ui;max-width:640px;margin:40px auto\"><h1>Color service consent</h1>${SECTIONS.map((s) => `<h3>${s.title}</h3><p>${s.body}</p>`).join(\"\")}<ul>${CLAUSES.filter((c) => agreed.includes(c.id))\n      .map((c) => `<li>☑ ${c.label}</li>`)\n      .join(\"\")}</ul><p>Signed by <b>${name}</b> on ${signed?.at}</p><img src=\"${sig}\" width=\"240\" alt=\"signature\"/></div>`\n    const url = URL.createObjectURL(new Blob([html], { type: \"text/html\" }))\n    const a = document.createElement(\"a\")\n    a.href = url\n    a.download = \"consent-signed.html\"\n    a.click()\n    URL.revokeObjectURL(url)\n  }\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <div className=\"mx-auto grid max-w-5xl gap-5 lg:grid-cols-[1fr_360px]\">\n        {/* Document */}\n        <section className=\"overflow-hidden rounded-2xl border bg-card shadow-xs\">\n          <div className=\"flex items-center justify-between gap-3 border-b px-5 py-4\">\n            <div className=\"flex items-center gap-3\">\n              <span className=\"flex size-9 items-center justify-center rounded-xl bg-primary/10 text-primary\">\n                <FileSignature className=\"size-4\" />\n              </span>\n              <div>\n                <h2 className=\"font-heading text-base font-semibold\">Color service consent</h2>\n                <div className=\"text-xs text-muted-foreground\">Studio Nine · v3 · 5 min read</div>\n              </div>\n            </div>\n            <div className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n              <span className={cn(\"transition-colors\", readAll && \"font-medium text-emerald-800 dark:text-emerald-400\")}>{readAll ? \"Read\" : `${Math.round(progress * 100)}% read`}</span>\n              <span className=\"h-1.5 w-20 overflow-hidden rounded-full bg-muted\" role=\"progressbar\" aria-label=\"Reading progress\" aria-valuenow={Math.round(progress * 100)} aria-valuemin={0} aria-valuemax={100}>\n                <span className={cn(\"block h-full rounded-full transition-[width]\", readAll ? \"bg-emerald-500\" : \"bg-primary\")} style={{ width: `${progress * 100}%` }} />\n              </span>\n            </div>\n          </div>\n          <div ref={scrollRef} onScroll={onScroll} className=\"max-h-[420px] overflow-y-auto px-5 py-4 text-sm leading-relaxed\" tabIndex={0} aria-label=\"Consent document\">\n            {SECTIONS.map((s, i) => (\n              <div key={s.title} className={cn(i > 0 && \"mt-5\")}>\n                <h3 className=\"font-medium\">\n                  {i + 1}. {s.title}\n                </h3>\n                <p className=\"mt-1 text-foreground/80\">{s.body}</p>\n              </div>\n            ))}\n            <div className=\"mt-6 rounded-xl bg-muted/60 p-3 text-xs text-muted-foreground\">End of document. You can now confirm the statements on the right.</div>\n          </div>\n        </section>\n\n        {/* Sign panel */}\n        <section className=\"space-y-4 rounded-2xl border bg-card p-5 shadow-xs\">\n          {signed ? (\n            <div className=\"flex flex-col items-center text-center\">\n              <SuccessCheck size={72} label=\"Consent signed\" />\n              <div className=\"mt-3 font-medium\">Signed and stored</div>\n              <div className=\"text-xs text-muted-foreground\">\n                {name} · {signed.at}\n              </div>\n              <div className=\"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground\">\n                <Lock className=\"size-3\" /> SHA-256 sealed · IP and time recorded\n              </div>\n              <Button className=\"mt-4\" size=\"sm\" variant=\"outline\" tone=\"neutral\" iconLeft={<Download />} onClick={download}>\n                Download signed copy\n              </Button>\n            </div>\n          ) : (\n            <>\n              <fieldset className={cn(\"space-y-2 transition-opacity\", !readAll && \"saturate-50 bg-muted/40 [&_.text-muted-foreground]:text-foreground/70\")}>\n                <legend className=\"mb-1 text-sm font-medium\">Confirm</legend>\n                {CLAUSES.map((c) => (\n                  <Checkbox key={c.id} size=\"sm\" disabled={!readAll} checked={agreed.includes(c.id)} onCheckedChange={(v) => setAgreed(v ? [...agreed, c.id] : agreed.filter((x) => x !== c.id))} label={c.label} />\n                ))}\n              </fieldset>\n              <Input label=\"Full legal name\" value={name} onValueChange={setName} placeholder=\"Maya Chen\" fullWidth />\n              <div>\n                <div className=\"mb-1.5 flex items-center justify-between\">\n                  <span className=\"text-sm font-medium\">Signature</span>\n                  <Button size=\"xs\" variant=\"ghost\" tone=\"neutral\" iconLeft={<Eraser />} onClick={clear} disabled={!hasInk}>\n                    Clear\n                  </Button>\n                </div>\n                <div className=\"relative\">\n                  <canvas\n                    ref={canvasRef}\n                    width={640}\n                    height={200}\n                    role=\"img\"\n                    aria-label=\"Signature pad. Draw your signature with your mouse or finger.\"\n                    onPointerDown={start}\n                    onPointerMove={move}\n                    onPointerUp={end}\n                    onPointerLeave={end}\n                    className=\"h-[120px] w-full touch-none rounded-xl border-2 border-dashed bg-muted/40 text-foreground\"\n                  />\n                  {!hasInk && (\n                    <span className=\"pointer-events-none absolute inset-0 flex items-center justify-center gap-1.5 text-xs text-muted-foreground\">\n                      <PenLine className=\"size-3.5\" /> Sign here\n                    </span>\n                  )}\n                  <span className=\"pointer-events-none absolute inset-x-6 bottom-6 border-b border-muted-foreground/30\" aria-hidden=\"true\" />\n                </div>\n              </div>\n              {error && (\n                <p role=\"alert\" className=\"text-xs text-rose-800 dark:text-rose-400\">\n                  {error}\n                </p>\n              )}\n              <Button fullWidth size=\"lg\" iconLeft={<Check />} loading={submitting} onClick={sign} animation=\"lift\">\n                Sign and submit\n              </Button>\n              <p className=\"flex items-center justify-center gap-1 text-[11px] text-muted-foreground\">\n                <ShieldCheck className=\"size-3\" /> Legally binding e-signature · stored for 7 years\n              </p>\n            </>\n          )}\n        </section>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/consent-form.tsx"
    }
  ],
  "categories": [
    "booking"
  ],
  "type": "registry:block"
}
