{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "waitlist-manager",
  "title": "Waitlist manager",
  "description": "Waitlist with priority reordering, open slots to offer, a 15-minute countdown on each offer, simulated accept/decline, auto-release of expired offers and a next-up card.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/avatar.json",
    "https://goodui.dev/r/button.json"
  ],
  "files": [
    {
      "path": "registry/blocks/scheduling/waitlist-manager.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ArrowDown, ArrowUp, BellRing, Check, Clock, Hourglass, Send, Sparkles, UserPlus, X } from \"lucide-react\"\nimport { Avatar } from \"@/components/goodui/avatar\"\nimport { Button } from \"@/components/goodui/button\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Model ---------- */\n\ntype Person = { id: number; name: string; service: string; wants: string; joined: string; offer?: { slot: string; expiresAt: number }; status: \"waiting\" | \"offered\" | \"booked\" | \"declined\" | \"expired\" }\ntype Slot = { id: string; label: string; staff: string; state: \"open\" | \"offered\" | \"booked\" }\n\nconst OFFER_SECONDS = 15 * 60\n\nconst INITIAL: Person[] = [\n  { id: 1, name: \"Jonas Weber\", service: \"Skin fade\", wants: \"Sat mornings\", joined: \"3 days ago\", status: \"waiting\" },\n  { id: 2, name: \"Aisha Khan\", service: \"Cut & style\", wants: \"Any weekday after 17:00\", joined: \"2 days ago\", status: \"waiting\" },\n  { id: 3, name: \"Sofia Rossi\", service: \"Balayage\", wants: \"Thu or Fri\", joined: \"Yesterday\", status: \"waiting\" },\n  { id: 4, name: \"Noah Fischer\", service: \"Beard trim\", wants: \"Lunchtime\", joined: \"Yesterday\", status: \"waiting\" },\n  { id: 5, name: \"Priya S.\", service: \"Gloss\", wants: \"Anytime\", joined: \"Today\", status: \"waiting\" },\n]\nconst SLOTS: Slot[] = [\n  { id: \"s1\", label: \"Sat 7 Nov · 09:30\", staff: \"Diego\", state: \"open\" },\n  { id: \"s2\", label: \"Thu 5 Nov · 17:30\", staff: \"Maya\", state: \"open\" },\n  { id: \"s3\", label: \"Fri 6 Nov · 12:15\", staff: \"Diego\", state: \"open\" },\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 mmss = (s: number) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, \"0\")}`\n\n/* ---------- Block ---------- */\n\nexport default function WaitlistManager() {\n  const [people, setPeople] = React.useState(INITIAL)\n  const [slots, setSlots] = React.useState(SLOTS)\n  const [tick, setTick] = React.useState<number | null>(null) // seconds since mount; null before mount\n  const [picked, setPicked] = React.useState<string>(SLOTS[0]!.id)\n  const [name, setName] = React.useState(\"\")\n  const [service, setService] = React.useState(\"Skin fade\")\n  const [announce, setAnnounce] = React.useState(\"\")\n  const nextId = React.useRef(10)\n\n  React.useEffect(() => {\n    setTick(0)\n    const t = setInterval(() => setTick((x) => (x === null ? 0 : x + 1)), 1000)\n    return () => clearInterval(t)\n  }, [])\n\n  // Expire offers and auto-offer the slot to the next person.\n  React.useEffect(() => {\n    if (tick === null) return\n    const expired = people.filter((p) => p.status === \"offered\" && p.offer && p.offer.expiresAt <= tick)\n    if (!expired.length) return\n    setPeople((l) => l.map((p) => (expired.some((e) => e.id === p.id) ? { ...p, status: \"expired\", offer: undefined } : p)))\n    for (const e of expired) {\n      const slotId = slots.find((s) => s.label === e.offer?.slot)?.id\n      if (slotId) {\n        setSlots((l) => l.map((s) => (s.id === slotId ? { ...s, state: \"open\" } : s)))\n        setAnnounce(`${e.name} didn't answer in time. ${e.offer?.slot} is open again.`)\n      }\n    }\n  }, [tick, people, slots])\n\n  const waiting = people.filter((p) => p.status === \"waiting\")\n  const offered = people.filter((p) => p.status === \"offered\")\n  const done = people.filter((p) => p.status === \"booked\" || p.status === \"declined\" || p.status === \"expired\")\n  const slot = slots.find((s) => s.id === picked)\n  const nextUp = waiting[0]\n\n  const offer = (personId: number, slotId: string) => {\n    if (tick === null) return\n    const s = slots.find((x) => x.id === slotId)\n    const p = people.find((x) => x.id === personId)\n    if (!s || !p || s.state !== \"open\") return\n    setSlots((l) => l.map((x) => (x.id === slotId ? { ...x, state: \"offered\" } : x)))\n    setPeople((l) => l.map((x) => (x.id === personId ? { ...x, status: \"offered\", offer: { slot: s.label, expiresAt: tick + OFFER_SECONDS } } : x)))\n    setAnnounce(`Offered ${s.label} to ${p.name}. They have 15 minutes.`)\n  }\n  const respond = (personId: number, accept: boolean) => {\n    const p = people.find((x) => x.id === personId)\n    if (!p?.offer) return\n    const slotId = slots.find((s) => s.label === p.offer?.slot)?.id\n    setPeople((l) => l.map((x) => (x.id === personId ? { ...x, status: accept ? \"booked\" : \"declined\", offer: accept ? x.offer : undefined } : x)))\n    if (slotId) setSlots((l) => l.map((s) => (s.id === slotId ? { ...s, state: accept ? \"booked\" : \"open\" } : s)))\n    setAnnounce(accept ? `${p.name} accepted ${p.offer.slot}. Booked.` : `${p.name} declined. ${p.offer.slot} is open again.`)\n  }\n  const moveP = (id: number, dir: -1 | 1) => {\n    setPeople((l) => {\n      const idx = l.findIndex((p) => p.id === id)\n      const j = idx + dir\n      if (idx < 0 || j < 0 || j >= l.length || l[j]!.status !== \"waiting\") return l\n      const copy = [...l]\n      ;[copy[idx], copy[j]] = [copy[j]!, copy[idx]!]\n      return copy\n    })\n  }\n  const remove = (id: number) => setPeople((l) => l.filter((p) => p.id !== id))\n  const add = (e: React.FormEvent) => {\n    e.preventDefault()\n    if (!name.trim()) return\n    setPeople((l) => [...l, { id: nextId.current++, name: name.trim(), service, wants: \"Anytime\", joined: \"Just now\", status: \"waiting\" }])\n    setName(\"\")\n  }\n  const requeue = (id: number) => setPeople((l) => l.map((p) => (p.id === id ? { ...p, status: \"waiting\", offer: undefined } : p)))\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <div className=\"mx-auto grid max-w-6xl gap-4 lg:grid-cols-[1fr_340px] [&>*]:min-w-0\">\n        {/* Queue */}\n        <section className=\"rounded-2xl border bg-card\" aria-label=\"Waitlist\">\n          <div className=\"flex flex-wrap items-center gap-2 border-b px-4 py-3\">\n            <Hourglass className=\"size-4 text-muted-foreground\" aria-hidden=\"true\" />\n            <h2 className=\"text-base font-semibold\">Waitlist</h2>\n            <span className=\"rounded-full bg-muted px-2 py-0.5 text-xs text-foreground/70 tabular-nums\">{waiting.length} waiting</span>\n            {offered.length > 0 && (\n              <span className=\"inline-flex items-center gap-1 rounded-full bg-amber-500/15 px-2 py-0.5 text-xs font-medium text-amber-800 dark:text-amber-300\">\n                <BellRing className=\"size-3\" aria-hidden=\"true\" /> {offered.length} offer{offered.length > 1 ? \"s\" : \"\"} out\n              </span>\n            )}\n          </div>\n          <p className=\"sr-only\" aria-live=\"polite\">\n            {announce}\n          </p>\n\n          {/* Pending offers */}\n          {offered.length > 0 && (\n            <ul className=\"divide-y border-b bg-amber-500/5\">\n              {offered.map((p) => {\n                const left = tick === null || !p.offer ? OFFER_SECONDS : Math.max(0, p.offer.expiresAt - tick)\n                const pct = (left / OFFER_SECONDS) * 100\n                return (\n                  <li key={p.id} className=\"flex flex-col gap-2 px-4 py-3 sm:flex-row sm:items-center sm:gap-4\">\n                    <Avatar name={p.name} size=\"md\" />\n                    <div className=\"min-w-0 flex-1\">\n                      <p className=\"text-sm font-semibold\">\n                        {p.name} <span className=\"font-normal text-muted-foreground\">· {p.service}</span>\n                      </p>\n                      <p className=\"text-xs text-muted-foreground\">\n                        Offered <span className=\"font-medium text-foreground\">{p.offer?.slot}</span> by SMS · waiting for a reply\n                      </p>\n                      <div className=\"mt-1.5 h-1.5 w-full max-w-xs overflow-hidden rounded-full bg-muted\" role=\"progressbar\" aria-label=\"Time left to accept\" aria-valuemin={0} aria-valuemax={OFFER_SECONDS} aria-valuenow={left}>\n                        <div className={cn(\"h-full rounded-full transition-[width] duration-1000 ease-linear\", left < 120 ? \"bg-rose-500\" : \"bg-amber-500\")} style={{ width: `${pct}%` }} />\n                      </div>\n                    </div>\n                    <div className=\"flex items-center gap-2\">\n                      <span className={cn(\"font-mono text-sm font-semibold tabular-nums\", left < 120 ? \"text-rose-700 dark:text-rose-300\" : \"text-amber-800 dark:text-amber-300\")}>\n                        <Clock className=\"mr-1 inline size-3.5 align-[-2px]\" aria-hidden=\"true\" />\n                        {mmss(left)}\n                      </span>\n                      <span className=\"mx-1 text-[11px] text-muted-foreground\">Simulate reply:</span>\n                      <Button size=\"xs\" tone=\"success\" iconLeft={<Check />} onClick={() => respond(p.id, true)}>\n                        Accepts\n                      </Button>\n                      <Button size=\"xs\" variant=\"outline\" tone=\"neutral\" iconLeft={<X />} onClick={() => respond(p.id, false)}>\n                        Declines\n                      </Button>\n                    </div>\n                  </li>\n                )\n              })}\n            </ul>\n          )}\n\n          <ol className=\"divide-y\">\n            {waiting.map((p, i) => (\n              <li key={p.id} className={cn(\"flex items-center gap-3 px-4 py-3\", i === 0 && \"bg-primary/5\")}>\n                <span className={cn(\"flex size-7 shrink-0 items-center justify-center rounded-full text-xs font-semibold tabular-nums\", i === 0 ? \"bg-primary text-primary-foreground\" : \"bg-muted text-foreground/70\")}>{i + 1}</span>\n                <Avatar name={p.name} size=\"sm\" />\n                <div className=\"min-w-0 flex-1\">\n                  <p className=\"truncate text-sm font-medium\">\n                    {p.name} <span className=\"font-normal text-foreground/70\">· {p.service}</span>\n                  </p>\n                  <p className=\"truncate text-xs text-foreground/70\">\n                    Wants {p.wants} · joined {p.joined}\n                  </p>\n                </div>\n                <div className=\"flex items-center gap-1\">\n                  <Button size=\"xs\" variant={i === 0 ? \"solid\" : \"soft\"} tone={i === 0 ? \"primary\" : \"neutral\"} iconLeft={<Send />} disabled={!slot || slot.state !== \"open\"} onClick={() => offer(p.id, picked)}>\n                    <span className=\"hidden sm:inline\">Offer</span> {slot ? slot.label.split(\" · \")[1] : \"\"}\n                  </Button>\n                  <button type=\"button\" aria-label={`Move ${p.name} up`} disabled={i === 0} onClick={() => moveP(p.id, -1)} className={cn(\"rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-30\", ring)}>\n                    <ArrowUp className=\"size-3.5\" />\n                  </button>\n                  <button type=\"button\" aria-label={`Move ${p.name} down`} disabled={i === waiting.length - 1} onClick={() => moveP(p.id, 1)} className={cn(\"rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-30\", ring)}>\n                    <ArrowDown className=\"size-3.5\" />\n                  </button>\n                  <button type=\"button\" aria-label={`Remove ${p.name} from the waitlist`} onClick={() => remove(p.id)} className={cn(\"rounded-md p-1 text-muted-foreground hover:bg-rose-500/10 hover:text-rose-700 dark:hover:text-rose-300\", ring)}>\n                    <X className=\"size-3.5\" />\n                  </button>\n                </div>\n              </li>\n            ))}\n            {waiting.length === 0 && <li className=\"px-4 py-10 text-center text-sm text-muted-foreground\">Nobody is waiting. Add someone below.</li>}\n          </ol>\n\n          <form onSubmit={add} className=\"flex flex-wrap items-center gap-2 border-t px-4 py-3\">\n            <UserPlus className=\"size-4 text-muted-foreground\" aria-hidden=\"true\" />\n            <label htmlFor=\"wl-name\" className=\"sr-only\">\n              Client name\n            </label>\n            <input id=\"wl-name\" value={name} onChange={(e) => setName(e.target.value)} placeholder=\"Add a client\" className={cn(\"h-8 min-w-0 flex-1 rounded-lg border bg-background px-2.5 text-sm\", ring)} />\n            <label htmlFor=\"wl-service\" className=\"sr-only\">\n              Service\n            </label>\n            <select id=\"wl-service\" value={service} onChange={(e) => setService(e.target.value)} className={cn(\"h-8 rounded-lg border bg-background px-2 text-xs\", ring)}>\n              {[\"Skin fade\", \"Cut & style\", \"Balayage\", \"Beard trim\", \"Gel manicure\"].map((s) => (\n                <option key={s}>{s}</option>\n              ))}\n            </select>\n            <Button size=\"sm\" type=\"submit\" variant=\"outline\" tone=\"neutral\" disabled={!name.trim()}>\n              Add\n            </Button>\n          </form>\n\n          {done.length > 0 && (\n            <ul className=\"divide-y border-t bg-muted/20\">\n              {done.map((p) => (\n                <li key={p.id} className=\"flex items-center gap-3 px-4 py-2 text-xs\">\n                  <Avatar name={p.name} size=\"xs\" />\n                  <span className=\"font-medium\">{p.name}</span>\n                  <span className={cn(\"rounded-full px-2 py-0.5 font-medium\", p.status === \"booked\" ? \"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300\" : p.status === \"expired\" ? \"bg-rose-500/12 text-rose-700 dark:text-rose-300\" : \"bg-muted text-foreground/70\")}>{p.status === \"booked\" ? `Booked ${p.offer?.slot}` : p.status === \"expired\" ? \"No reply in 15 min\" : \"Declined\"}</span>\n                  {p.status !== \"booked\" && (\n                    <Button size=\"xs\" variant=\"ghost\" tone=\"neutral\" className=\"ml-auto\" onClick={() => requeue(p.id)}>\n                      Back on the list\n                    </Button>\n                  )}\n                </li>\n              ))}\n            </ul>\n          )}\n        </section>\n\n        {/* Open slots */}\n        <aside className=\"flex flex-col gap-4\">\n          <div className=\"rounded-2xl border bg-card p-4\">\n            <div className=\"flex items-center gap-2\">\n              <Sparkles className=\"size-4 text-primary\" aria-hidden=\"true\" />\n              <h3 className=\"text-sm font-semibold\">Slots that just opened</h3>\n            </div>\n            <p className=\"mt-0.5 text-xs text-muted-foreground\">Pick one, then offer it to whoever is next.</p>\n            <div role=\"radiogroup\" aria-label=\"Open slots\" className=\"mt-3 flex flex-col gap-2\">\n              {slots.map((s) => (\n                <button key={s.id} type=\"button\" role=\"radio\" aria-checked={picked === s.id} disabled={s.state !== \"open\"} onClick={() => setPicked(s.id)} className={cn(\"flex items-center gap-3 rounded-xl border p-3 text-left text-sm transition-colors disabled:opacity-60\", picked === s.id && s.state === \"open\" ? \"border-primary bg-primary/5\" : \"bg-background hover:bg-muted/50\", ring)}>\n                  <span className={cn(\"size-2.5 rounded-full\", s.state === \"open\" ? \"bg-emerald-500\" : s.state === \"offered\" ? \"bg-amber-500 motion-safe:animate-pulse\" : \"bg-muted-foreground/40\")} aria-hidden=\"true\" />\n                  <span className=\"flex-1\">\n                    <span className=\"block font-medium tabular-nums\">{s.label}</span>\n                    <span className=\"block text-xs text-foreground/70\">with {s.staff}</span>\n                  </span>\n                  <span className=\"text-[11px] font-medium text-foreground/70 capitalize\">{s.state}</span>\n                </button>\n              ))}\n            </div>\n          </div>\n          {nextUp && slot?.state === \"open\" && (\n            <div className=\"rounded-2xl border bg-gradient-to-br from-primary/10 to-card p-4\">\n              <p className=\"text-xs font-medium text-muted-foreground\">Next up</p>\n              <div className=\"mt-2 flex items-center gap-3\">\n                <Avatar name={nextUp.name} size=\"md\" />\n                <div className=\"min-w-0 flex-1\">\n                  <p className=\"truncate text-sm font-semibold\">{nextUp.name}</p>\n                  <p className=\"truncate text-xs text-muted-foreground\">\n                    {nextUp.service} · wants {nextUp.wants}\n                  </p>\n                </div>\n              </div>\n              <Button fullWidth className=\"mt-3\" iconLeft={<Send />} onClick={() => offer(nextUp.id, picked)}>\n                Offer {slot.label}\n              </Button>\n              <p className=\"mt-2 text-[11px] text-muted-foreground\">They get an SMS with a one-tap link and 15 minutes to accept. If they don't, the slot comes back here.</p>\n            </div>\n          )}\n        </aside>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/waitlist-manager.tsx"
    }
  ],
  "categories": [
    "scheduling"
  ],
  "type": "registry:block"
}
