{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "day-agenda",
  "title": "Day agenda",
  "description": "Timeline agenda with a moving current-time line, now/next cards, overlapping bookings packed into columns, and drag-to-resize that snaps to 15 minutes (Shift+arrows on the keyboard).",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/avatar.json",
    "https://goodui.dev/r/button.json"
  ],
  "files": [
    {
      "path": "registry/blocks/scheduling/day-agenda.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeft, ChevronRight, GripHorizontal, Pause, Play } from \"lucide-react\"\nimport { Avatar } from \"@/components/goodui/avatar\"\nimport { Button } from \"@/components/goodui/button\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Demo data ---------- */\n\ntype Ev = { id: number; start: number; end: number; title: string; client: string; staff: string; tone: string }\nconst START_H = 8\nconst END_H = 19\nconst PX_PER_MIN = 1.4\nconst SNAP = 15\n\nconst TONES = {\n  maya: \"border-violet-500/50 bg-violet-500/12 text-violet-900 dark:text-violet-100\",\n  diego: \"border-sky-500/50 bg-sky-500/12 text-sky-900 dark:text-sky-100\",\n  lena: \"border-rose-500/50 bg-rose-500/12 text-rose-900 dark:text-rose-100\",\n  priya: \"border-emerald-500/50 bg-emerald-500/12 text-emerald-900 dark:text-emerald-100\",\n}\n\nconst INITIAL: Ev[] = [\n  { id: 1, start: 9 * 60, end: 11 * 60 + 30, title: \"Balayage\", client: \"Maya Chen\", staff: \"Priya Shah\", tone: TONES.priya },\n  { id: 2, start: 9 * 60 + 30, end: 10 * 60, title: \"Beard trim\", client: \"Omar Haddad\", staff: \"Diego Ramos\", tone: TONES.diego },\n  { id: 3, start: 9 * 60 + 45, end: 10 * 60 + 45, title: \"Gel manicure\", client: \"Lena P.\", staff: \"Lena Park\", tone: TONES.lena },\n  { id: 4, start: 10 * 60 + 15, end: 11 * 60, title: \"Skin fade\", client: \"Jonas Weber\", staff: \"Diego Ramos\", tone: TONES.diego },\n  { id: 5, start: 11 * 60 + 30, end: 12 * 60 + 15, title: \"Cut & style\", client: \"Aisha Khan\", staff: \"Maya Okafor\", tone: TONES.maya },\n  { id: 6, start: 12 * 60 + 30, end: 13 * 60 + 30, title: \"Lunch\", client: \"\", staff: \"Everyone\", tone: \"border-dashed border-border bg-muted/60 text-foreground/70\" },\n  { id: 7, start: 13 * 60 + 30, end: 15 * 60, title: \"Highlights\", client: \"Sofia Rossi\", staff: \"Priya Shah\", tone: TONES.priya },\n  { id: 8, start: 14 * 60, end: 14 * 60 + 45, title: \"Nail art\", client: \"Noah F.\", staff: \"Lena Park\", tone: TONES.lena },\n  { id: 9, start: 14 * 60 + 30, end: 15 * 60 + 15, title: \"Beard + cut\", client: \"Diego M.\", staff: \"Diego Ramos\", tone: TONES.diego },\n  { id: 10, start: 15 * 60 + 30, end: 17 * 60, title: \"Bridal trial\", client: \"Sofia R.\", staff: \"Maya Okafor\", tone: TONES.maya },\n  { id: 11, start: 17 * 60 + 15, end: 18 * 60, title: \"Gloss\", client: \"Jonas W.\", staff: \"Priya Shah\", tone: TONES.priya },\n]\n\nconst ring = \"outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-1 focus-visible:ring-offset-background\"\nconst fmt = (m: number) => `${String(Math.floor(m / 60)).padStart(2, \"0\")}:${String(m % 60).padStart(2, \"0\")}`\nconst y = (m: number) => (m - START_H * 60) * PX_PER_MIN\n\n// Column packing for overlapping events: each cluster gets as many columns as its max concurrency.\nfunction layout(events: Ev[]) {\n  const sorted = [...events].sort((a, b) => a.start - b.start || b.end - a.end)\n  const out = new Map<number, { col: number; cols: number }>()\n  let cluster: Ev[] = []\n  let clusterEnd = -1\n  const flush = () => {\n    const cols: number[] = []\n    const assign = new Map<number, number>()\n    for (const e of cluster) {\n      let c = cols.findIndex((end) => end <= e.start)\n      if (c < 0) {\n        c = cols.length\n        cols.push(0)\n      }\n      cols[c] = e.end\n      assign.set(e.id, c)\n    }\n    for (const e of cluster) out.set(e.id, { col: assign.get(e.id)!, cols: cols.length })\n    cluster = []\n  }\n  for (const e of sorted) {\n    if (cluster.length && e.start >= clusterEnd) flush()\n    cluster.push(e)\n    clusterEnd = Math.max(clusterEnd, e.end)\n  }\n  if (cluster.length) flush()\n  return out\n}\n\n/* ---------- Block ---------- */\n\nexport default function DayAgenda() {\n  const [events, setEvents] = React.useState(INITIAL)\n  const [now, setNow] = React.useState<number | null>(null) // minutes; null until mounted\n  const [running, setRunning] = React.useState(true)\n  const [resizing, setResizing] = React.useState<{ id: number; startY: number; end: number } | null>(null)\n  const [selected, setSelected] = React.useState<number | null>(null)\n  const [announce, setAnnounce] = React.useState(\"\")\n  const [dayOffset, setDayOffset] = React.useState(0)\n  const scroller = React.useRef<HTMLDivElement>(null)\n\n  // A simulated clock starting at 10:42 so the \"now\" line is always inside the day. Starts after mount.\n  React.useEffect(() => {\n    setNow(10 * 60 + 42)\n  }, [])\n  React.useEffect(() => {\n    if (!running || now === null) return\n    const t = setInterval(() => setNow((n) => (n === null ? n : n + 1 > END_H * 60 ? START_H * 60 : n + 1)), 1500)\n    return () => clearInterval(t)\n  }, [running, now === null])\n  React.useEffect(() => {\n    if (now !== null && scroller.current) scroller.current.scrollTop = Math.max(0, y(now) - 160)\n  }, [now === null])\n\n  const pos = layout(events)\n  const onResizeStart = (e: React.PointerEvent, ev: Ev) => {\n    e.preventDefault()\n    e.stopPropagation()\n    ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)\n    setResizing({ id: ev.id, startY: e.clientY, end: ev.end })\n  }\n  const onResizeMove = (e: React.PointerEvent) => {\n    if (!resizing) return\n    const ev = events.find((x) => x.id === resizing.id)\n    if (!ev) return\n    const delta = (e.clientY - resizing.startY) / PX_PER_MIN\n    const end = Math.max(ev.start + SNAP, Math.min(END_H * 60, Math.round((resizing.end + delta) / SNAP) * SNAP))\n    if (end !== ev.end) setEvents((l) => l.map((x) => (x.id === ev.id ? { ...x, end } : x)))\n  }\n  const onResizeEnd = () => {\n    if (!resizing) return\n    const ev = events.find((x) => x.id === resizing.id)\n    if (ev) setAnnounce(`${ev.title} now ends at ${fmt(ev.end)}.`)\n    setResizing(null)\n  }\n  const keyResize = (ev: Ev, delta: number) => {\n    const end = Math.max(ev.start + SNAP, Math.min(END_H * 60, ev.end + delta))\n    setEvents((l) => l.map((x) => (x.id === ev.id ? { ...x, end } : x)))\n    setAnnounce(`${ev.title} now ends at ${fmt(end)}.`)\n  }\n\n  const hours = Array.from({ length: END_H - START_H + 1 }, (_, i) => START_H + i)\n  const current = now === null ? null : events.find((e) => e.start <= now && now < e.end && e.client)\n  const next = now === null ? null : events.filter((e) => e.start > now && e.client).sort((a, b) => a.start - b.start)[0]\n  const dayLabel = [\"Tue, Nov 3\", \"Wed, Nov 4\", \"Thu, Nov 5\", \"Mon, Nov 2\", \"Sun, Nov 1\"][dayOffset >= 0 ? dayOffset % 3 : 3 + ((-dayOffset - 1) % 2)]\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <div className=\"mx-auto flex max-w-4xl flex-col gap-3\">\n        <div className=\"flex flex-wrap items-center justify-between gap-3\">\n          <div className=\"flex items-center gap-2\">\n            <Button variant=\"ghost\" tone=\"neutral\" size=\"xs\" iconOnly aria-label=\"Previous day\" onClick={() => setDayOffset((d) => d - 1)}>\n              <ChevronLeft />\n            </Button>\n            <h2 className=\"text-lg font-semibold tracking-tight\">{dayLabel}</h2>\n            <Button variant=\"ghost\" tone=\"neutral\" size=\"xs\" iconOnly aria-label=\"Next day\" onClick={() => setDayOffset((d) => d + 1)}>\n              <ChevronRight />\n            </Button>\n            <span className=\"rounded-full bg-muted px-2 py-0.5 text-xs text-foreground/70 tabular-nums\">{events.filter((e) => e.client).length} bookings</span>\n          </div>\n          <div className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n            {now !== null && (\n              <span className=\"font-mono tabular-nums\">\n                <span className=\"mr-1 inline-block size-2 rounded-full bg-rose-500 align-middle motion-safe:animate-pulse\" aria-hidden=\"true\" />\n                {fmt(now)}\n              </span>\n            )}\n            <Button variant=\"outline\" tone=\"neutral\" size=\"xs\" iconLeft={running ? <Pause /> : <Play />} onClick={() => setRunning((r) => !r)} aria-pressed={!running}>\n              {running ? \"Pause clock\" : \"Run clock\"}\n            </Button>\n          </div>\n        </div>\n\n        {/* Now / next strip */}\n        <div className=\"grid gap-3 sm:grid-cols-2\">\n          <div className=\"flex items-center gap-3 rounded-2xl border bg-card p-3\">\n            <span className=\"text-[11px] font-medium tracking-wide text-muted-foreground uppercase\">Now</span>\n            {current ? (\n              <>\n                <Avatar name={current.client} size=\"sm\" />\n                <span className=\"min-w-0 flex-1 text-sm\">\n                  <span className=\"block truncate font-medium\">{current.title} · {current.client}</span>\n                  <span className=\"block text-xs text-muted-foreground\">\n                    {fmt(current.start)}–{fmt(current.end)} with {current.staff.split(\" \")[0]}\n                  </span>\n                </span>\n                {now !== null && <span className=\"text-xs text-muted-foreground tabular-nums\">{current.end - now} min left</span>}\n              </>\n            ) : (\n              <span className=\"text-sm text-muted-foreground\">{now === null ? \"…\" : \"No one in the chair\"}</span>\n            )}\n          </div>\n          <div className=\"flex items-center gap-3 rounded-2xl border bg-card p-3\">\n            <span className=\"text-[11px] font-medium tracking-wide text-muted-foreground uppercase\">Next</span>\n            {next ? (\n              <>\n                <Avatar name={next.client} size=\"sm\" />\n                <span className=\"min-w-0 flex-1 text-sm\">\n                  <span className=\"block truncate font-medium\">{next.title} · {next.client}</span>\n                  <span className=\"block text-xs text-muted-foreground\">\n                    {fmt(next.start)} with {next.staff.split(\" \")[0]}\n                  </span>\n                </span>\n                {now !== null && <span className=\"text-xs text-muted-foreground tabular-nums\">in {next.start - now} min</span>}\n              </>\n            ) : (\n              <span className=\"text-sm text-muted-foreground\">{now === null ? \"…\" : \"Nothing more today\"}</span>\n            )}\n          </div>\n        </div>\n\n        <p className=\"sr-only\" aria-live=\"polite\">\n          {announce}\n        </p>\n\n        {/* Timeline */}\n        <div ref={scroller} className=\"relative h-[520px] overflow-y-auto rounded-2xl border bg-card\" onPointerMove={onResizeMove} onPointerUp={onResizeEnd} onPointerCancel={onResizeEnd}>\n          <div className=\"relative\" style={{ height: y(END_H * 60) + 24 }}>\n            {/* Hour lines */}\n            {hours.map((h) => (\n              <div key={h} className=\"absolute inset-x-0 flex items-start\" style={{ top: y(h * 60) }}>\n                <span className=\"w-14 shrink-0 -translate-y-2 pr-2 text-right font-mono text-[11px] text-muted-foreground tabular-nums\">{String(h).padStart(2, \"0\")}:00</span>\n                <span className=\"h-px flex-1 bg-border\" aria-hidden=\"true\" />\n              </div>\n            ))}\n            {hours.slice(0, -1).map((h) => (\n              <span key={`half-${h}`} className=\"absolute right-0 left-14 h-px bg-border/50\" style={{ top: y(h * 60 + 30) }} aria-hidden=\"true\" />\n            ))}\n\n            {/* Events */}\n            <div className=\"absolute inset-y-0 right-3 left-16\">\n              {events.map((ev) => {\n                const p = pos.get(ev.id) ?? { col: 0, cols: 1 }\n                const w = 100 / p.cols\n                const isSel = selected === ev.id\n                const past = now !== null && ev.end <= now\n                return (\n                  <div\n                    key={ev.id}\n                    role=\"button\"\n                    tabIndex={0}\n                    onClick={() => setSelected(isSel ? null : ev.id)}\n                    onKeyDown={(e) => {\n                      if (e.shiftKey && e.key === \"ArrowDown\") keyResize(ev, SNAP)\n                      else if (e.shiftKey && e.key === \"ArrowUp\") keyResize(ev, -SNAP)\n                      else if (e.key === \"Enter\" || e.key === \" \") setSelected(isSel ? null : ev.id)\n                      else return\n                      e.preventDefault()\n                    }}\n                    style={{ top: y(ev.start), height: Math.max(22, y(ev.end) - y(ev.start) - 2), left: `calc(${p.col * w}% + ${p.col ? 3 : 0}px)`, width: `calc(${w}% - ${p.cols > 1 ? 3 : 0}px)` }}\n                    className={cn(\"absolute overflow-hidden rounded-lg border-l-[3px] px-2 py-1 text-left text-xs shadow-sm transition-[box-shadow,opacity]\", ev.tone, past && \"opacity-80\", isSel && \"z-10 ring-2 ring-primary\", resizing?.id === ev.id && \"z-10 shadow-lg\", ring)}\n                  >\n                    <div className=\"truncate font-semibold leading-4\">{ev.title}</div>\n                    <span className=\"sr-only\">{fmt(ev.start)} to {fmt(ev.end)}. Shift plus up or down arrow changes the end time.</span>\n                    {ev.end - ev.start >= 40 && (\n                      <div className=\"truncate text-[11px] leading-4 opacity-85\">\n                        {fmt(ev.start)}–{fmt(ev.end)}\n                        {ev.client && ` · ${ev.client}`}\n                      </div>\n                    )}\n                    {ev.end - ev.start >= 70 && ev.client && <div className=\"mt-0.5 truncate text-[11px] opacity-85\">{ev.staff}</div>}\n                    <div\n                      onPointerDown={(e) => onResizeStart(e, ev)}\n                      className=\"absolute inset-x-0 bottom-0 flex h-3 cursor-ns-resize items-center justify-center opacity-0 transition-opacity hover:opacity-100 [[role=button]:focus-visible_&]:opacity-100 [[role=button]:hover_&]:opacity-100\"\n                      aria-hidden=\"true\"\n                    >\n                      <GripHorizontal className=\"size-3 opacity-70\" />\n                    </div>\n                  </div>\n                )\n              })}\n            </div>\n\n            {/* Current time line */}\n            {now !== null && (\n              <div className=\"pointer-events-none absolute inset-x-0 z-20 flex items-center transition-[top] duration-700\" style={{ top: y(now) }} aria-hidden=\"true\">\n                <span className=\"w-14 pr-2 text-right font-mono text-[10px] font-semibold text-rose-600 tabular-nums dark:text-rose-400\">{fmt(now)}</span>\n                <span className=\"size-2.5 -ml-1 rounded-full bg-rose-500 shadow-[0_0_0_3px_color-mix(in_oklab,var(--color-rose-500)_25%,transparent)]\" />\n                <span className=\"h-0.5 flex-1 bg-rose-500\" />\n              </div>\n            )}\n          </div>\n        </div>\n        <p className=\"text-[11px] text-muted-foreground\">Drag the bottom edge of a booking to change its length (snaps to 15 min). Overlapping bookings share the width.</p>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/day-agenda.tsx"
    }
  ],
  "categories": [
    "scheduling"
  ],
  "type": "registry:block"
}
