{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"restaurant-reservation-book-time-picker-with-a-pencil-on-a-string-that-writes-your-table-into-a-free-line","type":"registry:component","title":"Restaurant Reservation Book Time Picker with a Pencil on a String That Writes Your Table into a Free Line","description":"Reservation picker drawn as a booking book: choose a free line and a pencil on a string writes your table in. Free React and Tailwind code, or HTML.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/restaurant-reservation-book-time-picker-with-a-pencil-on-a-string-that-writes-your-table-into-a-free-line.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\n\nconst PLACE = \"Osteria Brandello\"; // small line under the book\nconst COVERS = 2; // the party size pencilled beside your name (2 to 8)\nconst OPEN_ON = 5; // weekday the book opens at (0 Sunday ... 6 Saturday), the next one after today\nconst AUTOPLAY = true; // the pencil books a couple of lines and turns a page until someone takes over\nconst SITTINGS = [\n  { name: \"Lunch\", times: [\"11:30 am\", \"12:00 pm\", \"12:30 pm\", \"1:00 pm\", \"1:30 pm\", \"2:00 pm\", \"2:30 pm\", \"3:00 pm\"] },\n  { name: \"Dinner\", times: [\"5:30 pm\", \"6:00 pm\", \"6:30 pm\", \"7:00 pm\", \"7:30 pm\", \"8:00 pm\", \"8:30 pm\", \"9:00 pm\"] },\n];\nconst FULLNESS = 0.52; // share of lines that already hold a name\n\nconst ID = \"restaurant-reservation-book\";\nconst DOW = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\nconst MON = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"];\nconst SERIF = 'Georgia, \"Times New Roman\", serif';\nconst noise = (f: number, o: number) => `url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='${f}' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='${o}'/%3E%3C/svg%3E\")`;\nconst FIBRE = noise(0.8, 0.5), LEATHER = noise(0.42, 0.9);\nconst rnd = (a: number, b: number, c: number) => { const n = Math.sin(a * 12.9898 + b * 78.233 + c * 37.719 + 4.1) * 43758.5453; return n - Math.floor(n); };\n// Who is already written on a line. The same day always gives the same page.\nconst entryAt = (day: number, part: number, row: number) => (rnd(day, part * 9 + row, 1) < FULLNESS ? { seed: Math.floor(rnd(day, row, part + 5) * 9000) + 11, covers: [2, 2, 3, 4, 4, 5, 6, 8][Math.floor(rnd(row, day, part + 2) * 8)], struck: rnd(day + 3, row, part) < 0.05 } : null);\n\n// A line of joined-up pencil writing: loops and humps that read as a name without spelling one.\nfunction scrawl(seed: number) {\n  let s = seed * 48271 + 7;\n  const r = () => { s = (s * 16807) % 2147483647; return s / 2147483647; };\n  const cap = () => `c ${4 + r() * 2} -2 ${6 + r() * 2} -${17 + r() * 3} ${3 + r()} -${17 + r() * 3} s -3 ${13 + r() * 2} ${6 + r() * 2} ${17 + r() * 3}`;\n  const letter = () => {\n    const k = 0.85 + r() * 0.4, p = r();\n    if (p < 0.34) return `q ${3 * k} -${6 + r() * 2} ${6 * k} 0`;\n    if (p < 0.62) return `c ${2 * k} 0 ${5 * k} -7 ${3 * k} -7 s ${-2 * k} 6 ${4.5 * k} 7`;\n    if (p < 0.76) return `q ${2 * k} ${3 + r() * 2} ${4 * k} 0`;\n    if (p < 0.9) return `c ${3 * k} -1 ${4 * k} -15 ${2 * k} -15 s ${-1 * k} 12 ${5 * k} 15`;\n    return `c ${3 * k} 0 ${3 * k} 9 0 9 s 0 -7 ${6 * k} -9`;\n  };\n  let d = `M3 29 ${cap()}`;\n  for (let i = 3 + Math.floor(r() * 3); i > 0; i--) d += ` ${letter()}`;\n  d += ` m ${7 + r() * 3} 0 ${cap()}`;\n  for (let i = 4 + Math.floor(r() * 4); i > 0; i--) d += ` ${letter()}`;\n  return d;\n}\nconst DIGIT: Record<number, string> = {\n  2: \"M9 18 q 5 -6 8 0 q 0 5 -8 11 h 9\", 3: \"M9 17 q 8 -4 7 2 q -1 4 -4 4 q 6 0 5 5 q -1 5 -9 2\", 4: \"M15 15 l -6 10 h 11 m -3 -5 v 10\",\n  5: \"M17 16 h -7 l -1 6 q 8 -3 8 3 q 0 6 -9 5\", 6: \"M16 15 q -8 4 -7 11 q 1 5 5 4 q 4 -1 3 -5 q -1 -4 -7 -1\", 8: \"M13 22 q -5 -4 0 -7 q 5 3 0 7 q -6 4 0 8 q 6 -4 0 -8\",\n};\nconst RING = \"M10 23 C 6 10, 50 6, 54 20 C 57 36, 12 40, 8 25 C 6 15, 20 9, 32 9\";\n\ntype Booking = { day: number; part: number; row: number; n: number };\n\n// One page of the book: a printed head and eight ruled lines, some already written on.\nfunction Sheet({ date, day, part, booking, onPick, live, rows }: { date: Date; day: number; part: number; booking: Booking; onPick?: (part: number, row: number) => void; live: boolean; rows?: { current: Record<string, HTMLElement | null> } }) {\n  const sit = SITTINGS[part], still = useReducedMotion();\n  return (\n    <div className={`relative h-full w-full overflow-hidden bg-[#f1e7d0] ${part === 0 ? \"sm:pr-5\" : \"sm:pl-5\"}`} style={{ fontFamily: SERIF }}>\n      <div className=\"absolute inset-0 mix-blend-multiply\" style={{ backgroundImage: FIBRE, opacity: 0.4 }} />\n      <div className={`absolute inset-0 hidden sm:block`} style={{ background: part === 0 ? \"linear-gradient(90deg,rgba(90,60,20,0.06) 0,rgba(255,255,255,0.14) 55%,rgba(255,255,255,0.2) 78%,rgba(70,44,12,0.12) 92%,rgba(40,24,6,0.42) 100%)\" : \"linear-gradient(270deg,rgba(90,60,20,0.08) 0,rgba(255,255,255,0.14) 55%,rgba(255,255,255,0.2) 78%,rgba(70,44,12,0.12) 92%,rgba(40,24,6,0.42) 100%)\" }} />\n      <div className={`absolute inset-0 sm:hidden`} style={{ background: part === 0 ? \"linear-gradient(180deg,rgba(255,255,255,0.1) 0,rgba(255,255,255,0.2) 86%,rgba(70,44,12,0.1) 96%,rgba(40,24,6,0.34) 100%)\" : \"linear-gradient(0deg,rgba(90,60,20,0.08) 0,rgba(255,255,255,0.2) 86%,rgba(70,44,12,0.1) 96%,rgba(40,24,6,0.34) 100%)\" }} />\n      <div className=\"relative flex h-[58px] items-end justify-between border-b-2 border-[#8d2f27] px-4 pb-2 sm:h-[78px] sm:px-6\">\n        <p className=\"flex items-baseline gap-2 text-[#8d2f27]\">\n          <span className=\"text-[30px] font-bold leading-none sm:text-[42px]\">{date.getDate()}</span>\n          <span className=\"text-[11px] font-bold uppercase leading-none tracking-[0.2em] sm:text-[12px]\">{DOW[date.getDay()]}<span className=\"hidden font-normal sm:inline\"> · {MON[date.getMonth()]}</span></span>\n        </p>\n        <p className=\"text-[11px] font-bold uppercase leading-none tracking-[0.26em] text-[#8d2f27] sm:text-[12px]\">{sit.name}</p>\n      </div>\n      <div className=\"relative\">\n        <span className=\"absolute bottom-0 left-[62px] top-0 w-px bg-[#c4674f]/60 sm:left-[76px]\" />\n        <span className=\"absolute bottom-0 right-[44px] top-0 w-px bg-[#c4674f]/60 sm:right-[52px]\" />\n        {sit.times.map((t, row) => {\n          const mine = booking.day === day && booking.part === part && booking.row === row, taken = mine ? null : entryAt(day, part, row), fresh = mine && booking.n > 0 && live && !still;\n          const pencil = { fill: \"none\", stroke: mine ? \"#2f2f36\" : \"#55555e\", strokeWidth: mine ? 1.5 : 1.25, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const, filter: `url(#${ID}-graphite)` };\n          const draw = (delay: number, duration: number) => (fresh ? { initial: { pathLength: 0, opacity: 0 }, animate: { pathLength: 1, opacity: 1 }, transition: { pathLength: { delay, duration, ease: \"linear\" as const }, opacity: { delay, duration: 0.01 } } } : {});\n          return (\n            <button\n              key={t}\n              ref={live && rows ? (el) => { rows.current[`${part}-${row}`] = el; } : undefined}\n              type=\"button\"\n              disabled={!!taken || !live}\n              tabIndex={live ? undefined : -1}\n              aria-pressed={live && !taken ? mine : undefined}\n              aria-label={`${t}, ${sit.name.toLowerCase()}, ${mine ? \"your table\" : taken ? \"taken\" : \"free\"}`}\n              onClick={() => onPick?.(part, row)}\n              className={`group relative flex h-[40px] w-full items-center border-b border-[#9fb2bf]/70 text-left outline-none sm:h-[46px] ${taken ? \"cursor-default\" : \"cursor-pointer hover:bg-[#8d2f27]/[0.05] focus-visible:bg-[#8d2f27]/[0.08] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#8d2f27]\"}`}\n            >\n              <span className=\"w-[62px] shrink-0 pl-4 text-[14px] font-bold leading-none text-[#8d2f27] sm:w-[76px] sm:pl-6 sm:text-[15px]\" style={{ fontVariantNumeric: \"lining-nums tabular-nums\" }}>{t.replace(/ [ap]m/, \"\")}</span>\n              {(taken || mine) && (\n                <svg aria-hidden=\"true\" className=\"pointer-events-none absolute left-[62px] top-1/2 h-[44px] w-[190px] -translate-y-1/2 overflow-visible sm:left-[78px]\" viewBox=\"0 0 190 44\">\n                  <g transform=\"translate(6 2) skewX(-12)\" style={{ transformOrigin: \"0 29px\" }}>\n                    <motion.path key={`n${booking.n}`} d={scrawl(mine ? 4242 : taken!.seed)} {...pencil} opacity={mine ? 1 : 0.86} {...draw(0.62, 0.8)} />\n                    {taken?.struck && <path d=\"M-2 22 q 50 -5 128 -1\" {...pencil} />}\n                  </g>\n                </svg>\n              )}\n              {(taken || mine) && !taken?.struck && (\n                <svg aria-hidden=\"true\" className=\"pointer-events-none absolute right-[8px] top-1/2 h-[44px] w-[30px] -translate-y-1/2 overflow-visible sm:right-[12px]\" viewBox=\"0 0 30 44\">\n                  <motion.path key={`c${booking.n}`} d={DIGIT[mine ? COVERS : taken!.covers] ?? DIGIT[2]} {...pencil} {...draw(1.44, 0.22)} />\n                </svg>\n              )}\n              {mine && (\n                <svg aria-hidden=\"true\" className=\"pointer-events-none absolute left-0 top-1/2 h-[44px] w-[62px] -translate-y-1/2 overflow-visible sm:left-[8px]\" viewBox=\"0 0 62 44\">\n                  <motion.path key={`r${booking.n}`} d={RING} {...pencil} {...draw(0.3, 0.32)} />\n                </svg>\n              )}\n              {!taken && !mine && live && <span className=\"ml-auto mr-[52px] font-sans text-[10px] uppercase tracking-[0.2em] text-[#8d2f27] opacity-0 group-hover:opacity-70 group-focus-visible:opacity-70 sm:mr-[64px]\">free</span>}\n            </button>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n\nexport default function RestaurantReservationBook() {\n  const reduce = useReducedMotion();\n  const [today] = useState(() => { const n = new Date(); return new Date(n.getFullYear(), n.getMonth(), n.getDate()); });\n  const [first] = useState(() => (((OPEN_ON - today.getDay()) % 7) + 7) % 7 || 7);\n  const [day, setDay] = useState(first);\n  const [booking, setBooking] = useState<Booking>(() => { let row = 3; while (row < 7 && entryAt(first, 1, row)) row++; return { day: first, part: 1, row, n: 0 }; });\n  const [flip, setFlip] = useState<{ from: number; to: number; dir: number } | null>(null);\n  const [stacked, setStacked] = useState(false);\n  const stage = useRef<HTMLDivElement>(null), book = useRef<HTMLDivElement>(null), eyelet = useRef<HTMLSpanElement>(null), pen = useRef<HTMLDivElement>(null), penTurn = useRef<HTMLDivElement>(null);\n  const twine = useRef<SVGPathElement>(null), twist = useRef<SVGPathElement>(null), shade = useRef<SVGPathElement>(null);\n  const rows = useRef<Record<string, HTMLElement | null>>({}), touched = useRef(false), api = useRef<{ write: (el: HTMLElement | null) => void; rest: () => void } | null>(null);\n  const live = useRef({ day, flip, booking }); live.current = { day, flip, booking };\n  const dateOf = (d: number) => new Date(today.getFullYear(), today.getMonth(), today.getDate() + d);\n\n  const pick = (part: number, row: number) => {\n    if (live.current.flip || row < 0) return;\n    const b = live.current.booking, d = live.current.day;\n    if (b.day === d && b.part === part && b.row === row) return;\n    setBooking({ day: d, part, row, n: b.n + 1 });\n    api.current?.write(rows.current[`${part}-${row}`] ?? null);\n  };\n  const turn = (dir: number) => {\n    if (live.current.flip) return;\n    const from = live.current.day, to = from + dir;\n    if (to < 0) return;\n    api.current?.rest(); setDay(to);\n    if (!reduce) setFlip({ from, to, dir });\n  };\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(max-width: 639px)\"), on = () => setStacked(mq.matches);\n    on(); mq.addEventListener(\"change\", on);\n    return () => mq.removeEventListener(\"change\", on);\n  }, []);\n\n  // The pencil and its string. The string is a chain of points dragged across the table with friction; the pencil is sprung towards wherever it is wanted.\n  useEffect(() => {\n    const st = stage.current, bk = book.current, ey = eyelet.current, pe = pen.current, pt = penTurn.current;\n    if (!st || !bk || !ey || !pe || !pt) return;\n    const N = 30, LEN = 222, RAD = Math.PI / 180, HOLD = 40, LIE = 9;\n    const P = new Float32Array(N * 2), O = new Float32Array(N * 2);\n    let g = { ax: 0, ay: 0, bx: 0, by: 0, bw: 0, bh: 0 }, seg = 10, raf = 0, seen = true, calm = 0;\n    const p = { x: 0, y: 0, a: LIE, vx: 0, vy: 0, va: 0 };\n    let aim = { x: 0, y: 0, a: LIE }, hover: { x: number; y: number } | null = null, script: { t0: number; x: number; y: number; w: number } | null = null;\n    const home = () => ({ x: g.bx + g.bw - Math.min(230, g.bw * 0.62), y: g.by + g.bh - 30, a: LIE });\n    const tail = (x: number, y: number, a: number) => [x + Math.cos(a * RAD) * LEN, y - Math.sin(a * RAD) * LEN];\n    const solve = (rounds: number) => {\n      const [ex, ey2] = tail(p.x, p.y, p.a);\n      for (let k = 0; k < rounds; k++) {\n        P[0] = g.ax; P[1] = g.ay; P[N * 2 - 2] = ex; P[N * 2 - 1] = ey2;\n        for (let i = 0; i < N - 1; i++) {\n          const dx = P[i * 2 + 2] - P[i * 2], dy = P[i * 2 + 3] - P[i * 2 + 1], d = Math.sqrt(dx * dx + dy * dy) || 0.001, f = ((d - seg) / d) * 0.5;\n          if (i > 0) { P[i * 2] += dx * f; P[i * 2 + 1] += dy * f; }\n          if (i < N - 2) { P[i * 2 + 2] -= dx * f; P[i * 2 + 3] -= dy * f; }\n        }\n        for (let i = 0; i < N - 2; i++) { // a little stiffness so the string cannot fold flat on itself\n          const dx = P[i * 2 + 4] - P[i * 2], dy = P[i * 2 + 5] - P[i * 2 + 1], d = Math.sqrt(dx * dx + dy * dy) || 0.001;\n          if (d < seg * 1.5) { const f = ((d - seg * 1.5) / d) * 0.12; if (i > 0) { P[i * 2] += dx * f; P[i * 2 + 1] += dy * f; } if (i < N - 3) { P[i * 2 + 4] -= dx * f; P[i * 2 + 5] -= dy * f; } }\n        }\n      }\n    };\n    const paint = () => {\n      let d = `M${P[0].toFixed(1)} ${P[1].toFixed(1)}`;\n      for (let i = 1; i < N - 1; i++) d += ` Q${P[i * 2].toFixed(1)} ${P[i * 2 + 1].toFixed(1)} ${((P[i * 2] + P[i * 2 + 2]) / 2).toFixed(1)} ${((P[i * 2 + 1] + P[i * 2 + 3]) / 2).toFixed(1)}`;\n      d += ` L${P[N * 2 - 2].toFixed(1)} ${P[N * 2 - 1].toFixed(1)}`;\n      twine.current?.setAttribute(\"d\", d); twist.current?.setAttribute(\"d\", d); shade.current?.setAttribute(\"d\", d);\n      pe.style.transform = `translate3d(${p.x.toFixed(1)}px,${(p.y - 9).toFixed(1)}px,0)`; pt.style.transform = `rotate(${(-p.a).toFixed(2)}deg)`;\n    };\n    const measure = () => {\n      const s = st.getBoundingClientRect(), b = bk.getBoundingClientRect(), e = ey.getBoundingClientRect();\n      g = { ax: e.left + e.width / 2 - s.left, ay: e.top + e.height / 2 - s.top, bx: b.left - s.left, by: b.top - s.top, bw: b.width, bh: b.height };\n      const h = home(); let reach = 0;\n      for (const [x, y, a] of [[h.x, h.y, h.a], [g.bx, g.by + g.bh, HOLD], [g.bx + g.bw, g.by + g.bh, HOLD], [g.bx, g.by, HOLD], [g.bx + g.bw, g.by, HOLD]]) { const [tx, ty] = tail(x, y, a); reach = Math.max(reach, Math.hypot(tx - g.ax, ty - g.ay)); }\n      seg = (reach + 24) / (N - 1);\n      p.x = h.x; p.y = h.y; p.a = h.a; p.vx = p.vy = p.va = 0; aim = h; script = null;\n      // lay the string out in a loose arc beside the straight line, then let it find its length\n      const [ex, ey2] = tail(p.x, p.y, p.a), cx = ex - g.ax, cy = ey2 - g.ay, c = Math.hypot(cx, cy) || 1, bow = Math.sqrt(Math.max(0, (seg * (N - 1)) ** 2 - c * c)) * 0.42;\n      for (let i = 0; i < N; i++) { const t = i / (N - 1), b2 = Math.sin(t * Math.PI) * bow; P[i * 2] = g.ax + cx * t - (cy / c) * b2 * (cx > 0 ? -1 : 1); P[i * 2 + 1] = g.ay + cy * t + (cx / c) * b2 * (cx > 0 ? -1 : 1); }\n      solve(60); O.set(P); paint();\n    };\n    const frame = (now: number) => {\n      raf = 0;\n      if (script) {\n        const e = (now - script.t0) / 1000, mid = script.y;\n        if (e < 0.3) aim = { x: script.x + 12, y: mid + 2, a: HOLD };\n        else if (e < 0.62) { const t = ((e - 0.3) / 0.32) * Math.PI * 2.5; aim = { x: script.x + 34 - Math.cos(t) * 22, y: mid - Math.sin(t) * 12, a: HOLD + Math.sin(t) * 3 }; }\n        else if (e < 1.42) { const u = (e - 0.62) / 0.8, nx = script.w < 300 ? 66 : 86; aim = { x: script.x + nx + u * 104, y: mid + 3 + Math.sin(u * 46) * 4, a: HOLD + Math.sin(u * 46) * 2.5 }; }\n        else if (e < 1.7) aim = { x: script.x + script.w - 24, y: mid + Math.sin((e - 1.42) * 30) * 5, a: HOLD };\n        else { script = null; aim = home(); }\n      } else aim = hover ? { x: hover.x, y: hover.y, a: HOLD } : home();\n      const k = script ? 420 : 150, c = script ? 30 : 20, dt = 1 / 60;\n      p.vx += (k * (aim.x - p.x) - c * p.vx) * dt; p.vy += (k * (aim.y - p.y) - c * p.vy) * dt; p.va += (120 * (aim.a - p.a) - 18 * p.va) * dt;\n      p.x += p.vx * dt; p.y += p.vy * dt; p.a += p.va * dt;\n      let moved = Math.abs(p.vx) + Math.abs(p.vy) + Math.abs(p.va);\n      for (let i = 1; i < N - 1; i++) { // dragged over the table: most of the speed is lost each step\n        const x = P[i * 2], y = P[i * 2 + 1], vx = (x - O[i * 2]) * 0.8, vy = (y - O[i * 2 + 1]) * 0.8;\n        O[i * 2] = x; O[i * 2 + 1] = y; P[i * 2] = x + vx; P[i * 2 + 1] = y + vy; moved += Math.abs(vx) + Math.abs(vy);\n      }\n      solve(8); paint();\n      calm = moved < 0.6 && !script ? calm + 1 : 0;\n      if (seen && !document.hidden && calm < 20) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { calm = 0; if (!raf && !reduce) raf = requestAnimationFrame(frame); };\n    api.current = {\n      write: (el) => { if (!el || reduce) return; const s = st.getBoundingClientRect(), r = el.getBoundingClientRect(); hover = null; script = { t0: performance.now(), x: r.left - s.left, y: r.top - s.top + r.height / 2, w: r.width }; wake(); },\n      rest: () => { script = null; hover = null; wake(); },\n    };\n    const onMove = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\" || script) return;\n      const s = st.getBoundingClientRect(), x = e.clientX - s.left, y = e.clientY - s.top;\n      hover = x > g.bx && x < g.bx + g.bw && y > g.by && y < g.by + g.bh ? { x: x + 7, y: y + 5 } : null; wake();\n    };\n    const onLeave = () => { hover = null; wake(); };\n    measure();\n    st.addEventListener(\"pointermove\", onMove); st.addEventListener(\"pointerleave\", onLeave);\n    const ro = new ResizeObserver(() => { measure(); wake(); }); ro.observe(st);\n    const io = new IntersectionObserver(([en]) => { seen = en.isIntersecting; if (seen) wake(); }); io.observe(st);\n    const onVis = () => { if (!document.hidden) wake(); };\n    document.addEventListener(\"visibilitychange\", onVis);\n    return () => { cancelAnimationFrame(raf); api.current = null; st.removeEventListener(\"pointermove\", onMove); st.removeEventListener(\"pointerleave\", onLeave); ro.disconnect(); io.disconnect(); document.removeEventListener(\"visibilitychange\", onVis); };\n  }, [reduce, stacked]);\n\n  useEffect(() => {\n    if (!AUTOPLAY || reduce) return;\n    let step = 0, timer = 0;\n    const freeRow = (d: number, part: number, start: number) => { for (let i = 0; i < 8; i++) { const r = (start + i) % 8; if (!entryAt(d, part, r) && !(live.current.booking.day === d && live.current.booking.part === part && live.current.booking.row === r)) return r; } return -1; };\n    const tick = () => {\n      if (touched.current || document.hidden) return;\n      const d = live.current.day, k = step++ % 4;\n      if (k === 0) pick(1, freeRow(d, 1, 5)); else if (k === 1) turn(1); else if (k === 2) pick(0, freeRow(d, 0, 2)); else turn(-1);\n    };\n    const start = window.setTimeout(() => { tick(); timer = window.setInterval(tick, 3200); }, 3100);\n    return () => { window.clearTimeout(start); window.clearInterval(timer); };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [reduce]);\n\n  const left = flip ? (flip.dir > 0 ? flip.from : flip.to) : day, right = flip ? (flip.dir > 0 ? flip.to : flip.from) : day;\n  const date = dateOf(day), mineDate = dateOf(booking.day), take = () => { touched.current = true; };\n  const arrow = \"flex h-10 w-10 items-center justify-center rounded-full text-[#d9c9b4] outline-none transition-colors hover:bg-white/10 hover:text-white focus-visible:ring-2 focus-visible:ring-white disabled:opacity-30 motion-reduce:transition-none\";\n  const sheet = (d: number, part: number, on: boolean) => <Sheet date={dateOf(d)} day={d} part={part} booking={booking} live={on} onPick={on ? (a, b) => { take(); pick(a, b); } : undefined} rows={on ? rows : undefined} />;\n\n  return (\n    <div ref={stage} className=\"relative flex min-h-[1000px] w-full flex-col items-center justify-center overflow-hidden bg-[#1b1512] px-3 py-12 sm:min-h-[780px] sm:px-6\" style={{ backgroundImage: \"radial-gradient(90% 75% at 42% 34%,#4a3a30 0%,#2a211c 48%,#15100d 100%)\" }}>\n      <svg aria-hidden=\"true\" className=\"absolute h-0 w-0\"><filter id={`${ID}-graphite`} x=\"-5%\" y=\"-20%\" width=\"110%\" height=\"140%\"><feTurbulence type=\"fractalNoise\" baseFrequency=\"0.9\" numOctaves=\"2\" seed=\"4\" result=\"t\" /><feDisplacementMap in=\"SourceGraphic\" in2=\"t\" scale=\"1.6\" /></filter></svg>\n      <div ref={book} className=\"relative w-full max-w-[380px] rounded-[14px] bg-[#5e211e] p-[10px] sm:max-w-[900px] sm:p-[15px]\" style={{ boxShadow: \"inset 0 1px 0 rgba(255,200,180,0.35), inset 0 0 0 1px rgba(0,0,0,0.4), 0 2px 0 #3d1412, 0 4px 0 #2e0f0d, 0 50px 60px -20px rgba(0,0,0,0.85), 0 16px 22px -6px rgba(0,0,0,0.6)\" }}>\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 rounded-[14px] mix-blend-overlay\" style={{ backgroundImage: LEATHER, opacity: 0.6 }} />\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-[4px] rounded-[11px] border border-dashed border-[#e8b89a]/45\" />\n        <span ref={eyelet} aria-hidden=\"true\" className=\"absolute left-1/2 top-[-3px] z-20 h-[13px] w-[13px] -translate-x-1/2 rounded-full\" style={{ background: \"radial-gradient(circle at 50% 50%,#140c08 0 32%,#8a6a2c 36%,#f1d58a 52%,#a8843a 70%,#5a4418 100%)\", boxShadow: \"0 1px 2px rgba(0,0,0,0.7)\" }} />\n        <div className=\"relative rounded-[3px]\" style={{ boxShadow: \"0 0 0 1px #cfc2a3, 1px 1px 0 1px #efe6d0, 2px 2px 0 1px #c9bc9c, 3px 3px 0 1px #efe6d0, 4px 4px 0 1px #bfb292, 5px 6px 6px rgba(0,0,0,0.5)\", perspective: 2400 }}>\n          <div role=\"group\" aria-label={`Reservations for ${DOW[date.getDay()]} ${date.getDate()} ${MON[date.getMonth()]}`} className=\"relative grid grid-cols-1 sm:grid-cols-2\">\n            <div className=\"relative\">{sheet(left, 0, !flip)}</div>\n            <div className=\"relative\">{sheet(right, 1, !flip)}</div>\n            {flip && (\n              <motion.div\n                aria-hidden=\"true\"\n                className={`absolute z-10 ${stacked ? \"inset-x-0 bottom-0 h-1/2\" : \"inset-y-0 right-0 w-1/2\"}`}\n                style={{ transformStyle: \"preserve-3d\", transformOrigin: stacked ? \"50% 0\" : \"0 50%\" }}\n                initial={stacked ? { rotateX: flip.dir > 0 ? 0 : 180 } : { rotateY: flip.dir > 0 ? 0 : -180 }}\n                animate={stacked ? { rotateX: flip.dir > 0 ? 180 : 0 } : { rotateY: flip.dir > 0 ? -180 : 0 }}\n                transition={{ duration: 0.8, ease: [0.45, 0.05, 0.3, 1] }}\n                onAnimationComplete={() => setFlip(null)}\n              >\n                <div className=\"absolute inset-0\" style={{ backfaceVisibility: \"hidden\", boxShadow: \"0 0 30px rgba(0,0,0,0.35)\" }}>{sheet(flip.dir > 0 ? flip.from : flip.to, 1, false)}</div>\n                <div className=\"absolute inset-0\" style={{ backfaceVisibility: \"hidden\", transform: stacked ? \"rotateX(180deg)\" : \"rotateY(180deg)\", boxShadow: \"0 0 30px rgba(0,0,0,0.35)\" }}>{sheet(flip.dir > 0 ? flip.to : flip.from, 0, false)}</div>\n              </motion.div>\n            )}\n          </div>\n        </div>\n        <svg aria-hidden=\"true\" className=\"pointer-events-none absolute left-1/2 top-[6px] z-10 hidden h-[calc(100%+40px)] w-[18px] -translate-x-1/2 overflow-visible sm:block\" viewBox=\"0 0 18 600\" preserveAspectRatio=\"none\">\n          <defs><linearGradient id={`${ID}-satin`} x1=\"0\" x2=\"1\" y1=\"0\" y2=\"0\"><stop offset=\"0\" stopColor=\"#0f3d4a\" /><stop offset=\"0.3\" stopColor=\"#2b8298\" /><stop offset=\"0.5\" stopColor=\"#7cc4d4\" /><stop offset=\"0.72\" stopColor=\"#1f6d82\" /><stop offset=\"1\" stopColor=\"#0c3340\" /></linearGradient></defs>\n          <path d=\"M3 0 C 0 150, 8 300, 4 450 S 8 560, 4 600 l 5 -8 l 5 8 C 18 560, 14 520, 15 450 S 11 150, 15 0 Z\" fill=\"rgba(0,0,0,0.4)\" transform=\"translate(3 2)\" />\n          <path d=\"M3 0 C 0 150, 8 300, 4 450 S 8 560, 4 600 l 5 -8 l 5 8 C 18 560, 14 520, 15 450 S 11 150, 15 0 Z\" fill={`url(#${ID}-satin)`} />\n        </svg>\n      </div>\n      <svg aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible\">\n        <path ref={shade} fill=\"none\" stroke=\"rgba(0,0,0,0.4)\" strokeWidth=\"3\" strokeLinecap=\"round\" transform=\"translate(2 4)\" style={{ filter: \"blur(1.5px)\" }} />\n        <path ref={twine} fill=\"none\" stroke=\"#d8c49a\" strokeWidth=\"2.6\" strokeLinecap=\"round\" />\n        <path ref={twist} fill=\"none\" stroke=\"#8a7447\" strokeWidth=\"2.6\" strokeDasharray=\"1.6 3.4\" opacity=\"0.8\" />\n      </svg>\n      <div ref={pen} aria-hidden=\"true\" className=\"pointer-events-none absolute left-0 top-0 z-30 h-[18px] w-[232px]\" style={{ filter: \"drop-shadow(5px 9px 4px rgba(0,0,0,0.5))\" }}>\n        <div ref={penTurn} className=\"h-full w-full\" style={{ transformOrigin: \"0 50%\" }}>\n          <svg width=\"232\" height=\"18\" viewBox=\"0 0 232 18\">\n            <defs>\n              <linearGradient id={`${ID}-brass`} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\"><stop offset=\"0\" stopColor=\"#fff3c4\" /><stop offset=\"0.3\" stopColor=\"#d8b25a\" /><stop offset=\"0.6\" stopColor=\"#8f6c22\" /><stop offset=\"1\" stopColor=\"#5a4210\" /></linearGradient>\n              <linearGradient id={`${ID}-rubber`} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\"><stop offset=\"0\" stopColor=\"#f6b3ac\" /><stop offset=\"0.5\" stopColor=\"#e2877f\" /><stop offset=\"1\" stopColor=\"#a9544e\" /></linearGradient>\n              <linearGradient id={`${ID}-cedar`} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\"><stop offset=\"0\" stopColor=\"#f3dcb6\" /><stop offset=\"0.5\" stopColor=\"#dcb886\" /><stop offset=\"1\" stopColor=\"#a47c4e\" /></linearGradient>\n            </defs>\n            <path d=\"M0 9 L13 6.2 L13 11.8 Z\" fill=\"#2b2b30\" /><path d=\"M0 9 L13 6.2 L13 8 Z\" fill=\"#5a5a62\" />\n            <path d=\"M13 6.2 L38 1 L38 17 L13 11.8 Z\" fill={`url(#${ID}-cedar)`} />\n            <path d=\"M38 1 q -5 2.6 0 5.3 q -5 2.7 0 5.4 q -5 2.6 0 5.3 H200 V1 Z\" fill=\"#e9b213\" />\n            <path d=\"M38 1 q -5 2.6 0 5.3 H200 V1 Z\" fill=\"#fad64b\" /><path d=\"M38 11.7 q -5 2.6 0 5.3 H200 V11.7 Z\" fill=\"#b07f06\" />\n            <path d=\"M40 2.2 H200\" stroke=\"#fff3b0\" strokeWidth=\"0.8\" opacity=\"0.8\" /><path d=\"M118 9 h30 M154 9 h10\" stroke=\"#7a5a08\" strokeWidth=\"1.6\" opacity=\"0.55\" />\n            <rect x=\"198\" y=\"0.5\" width=\"19\" height=\"17\" rx=\"1\" fill={`url(#${ID}-brass)`} /><path d=\"M202 1v16M205 1v16M210 1v16M213 1v16\" stroke=\"#4d380c\" strokeWidth=\"0.7\" opacity=\"0.6\" />\n            <path d=\"M217 1 H226 q 6 0 6 8 q 0 8 -6 8 H217 Z\" fill={`url(#${ID}-rubber)`} />\n          </svg>\n        </div>\n      </div>\n      <div className=\"relative z-40 mt-12 flex items-center gap-1\">\n        <button type=\"button\" onClick={() => { take(); turn(-1); }} disabled={day <= 0} aria-label=\"Previous day\" className={arrow}>\n          <svg aria-hidden=\"true\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M12 4.5 6.5 10l5.5 5.5\" /></svg>\n        </button>\n        <p aria-live=\"polite\" className=\"min-w-[236px] text-center\">\n          <span className=\"block text-[17px] font-semibold leading-6 tracking-tight text-white\">{DOW[mineDate.getDay()]} {mineDate.getDate()} {MON[mineDate.getMonth()]}, {SITTINGS[booking.part].times[booking.row]}</span>\n          <span className=\"block font-mono text-[11px] uppercase leading-5 tracking-[0.16em] text-[#d9c9b4]\">{PLACE} <span className=\"mx-1 hidden text-[#8f7f6c] sm:inline\">/</span> <span className=\"block sm:inline\">table for {COVERS}, in pencil</span></span>\n        </p>\n        <button type=\"button\" onClick={() => { take(); turn(1); }} aria-label=\"Next day\" className={arrow}>\n          <svg aria-hidden=\"true\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"m8 4.5 5.5 5.5L8 15.5\" /></svg>\n        </button>\n      </div>\n    </div>\n  );\n}\n"}]}
