{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ctas-03",
  "title": "Call to action with a queue",
  "description": "A closing band with an email field that checks, sends and confirms, beside a queue of conversations whose marks swap into drawn checks and whose rows dim into Done while the block is on screen.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/drawn-check.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/wash.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/ctas/ctas-03/index.tsx",
      "content": "'use client';\n\nimport { useEffect, useId } from 'react';\n\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport { SECTION } from './data';\nimport { EmailForm } from './email-form';\nimport { QueueCard } from './queue-card';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  resolvedCountOf,\n  SCRIPT,\n  SEND_MS,\n  type CtaState,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nfunction spokenLineOf(state: CtaState) {\n  if (state.form === 'invalid') {\n    return 'Enter an address like name@company.com';\n  }\n  if (state.form === 'sending') {\n    return 'Sending your sign-in link';\n  }\n  if (state.form === 'sent') {\n    return `We sent a sign-in link to ${state.sentTo}`;\n  }\n  return '';\n}\n\nexport default function Ctas03() {\n  const { ref, isAutoplaying, state, act, pressed, isFinished, restart } =\n    useSession(SESSION);\n  const titleId = useId();\n  const isSending = state.form === 'sending';\n  const resolved = resolvedCountOf(state);\n  const message = spokenUnless(isAutoplaying, spokenLineOf(state));\n  const canReplay = isFinished && !isAutoplaying;\n\n  useKeptHeight(ref);\n\n  useEffect(() => {\n    if (!isSending) {\n      return;\n    }\n    const timer = setTimeout(() => act({ type: 'sent' }), SEND_MS);\n    return () => clearTimeout(timer);\n  }, [isSending, act]);\n\n  return (\n    <div ref={ref} className='@container min-h-[33rem]'>\n      <section\n        aria-labelledby={titleId}\n        className='px-4 py-12 @2xl:px-6 @2xl:py-16 @5xl:px-8'\n      >\n        <div className='surface-brand relative isolate mx-auto grid max-w-6xl grid-cols-1 gap-8 rounded-2xl p-6 @2xl:p-10 @3xl:grid-cols-[minmax(0,1fr)_minmax(0,22rem)] @3xl:items-center @3xl:gap-12'>\n          <Wash />\n          <div className='flex flex-col gap-6'>\n            <div className='flex max-w-xl flex-col gap-2'>\n              <h2\n                id={titleId}\n                className='text-2xl font-semibold text-balance @2xl:text-3xl'\n              >\n                {SECTION.title}\n              </h2>\n              <p className='text-muted-foreground text-base text-pretty'>\n                {SECTION.description}\n              </p>\n            </div>\n            <EmailForm\n              email={state.email}\n              form={state.form}\n              attempts={state.attempts}\n              sentTo={state.sentTo}\n              isPressed={pressed === 'submit'}\n              onType={(value) => act({ type: 'typed', value })}\n              onSubmit={() => act({ type: 'submitted' })}\n              onReset={() => act({ type: 'reset' })}\n            />\n            <div className='flex'>\n              <ReplayButton\n                isShown={canReplay}\n                onReplay={restart}\n                label='Replay'\n              />\n            </div>\n          </div>\n          <QueueCard tasks={state.tasks} resolved={resolved} />\n        </div>\n      </section>\n      <LiveRegion message={message} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ctas-03/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ctas/ctas-03/email-form.tsx",
      "content": "'use client';\n\nimport { useAnimate } from 'motion/react';\nimport { useEffect, useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowRightIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\n\nimport { SECTION } from './data';\nimport type { FormStatus } from './session';\n\nconst LABELS: Record<MorphState, string> = {\n  idle: 'Get started',\n  busy: 'Sending',\n  done: 'Sent',\n};\n\nconst NUDGE = { x: [0, -4, 4, -2, 0] };\n\nconst NUDGE_TRANSITION = { duration: 0.3 };\n\nfunction morphStateOf(form: FormStatus): MorphState {\n  if (form === 'sending') {\n    return 'busy';\n  }\n  if (form === 'sent') {\n    return 'done';\n  }\n  return 'idle';\n}\n\nfunction describedByOf(isInvalid: boolean, hintId: string) {\n  if (isInvalid) {\n    return hintId;\n  }\n  return undefined;\n}\n\ntype EmailFormProps = {\n  email: string;\n  form: FormStatus;\n  attempts: number;\n  sentTo: string;\n  isPressed: boolean;\n  onType: (value: string) => void;\n  onSubmit: () => void;\n  onReset: () => void;\n};\n\nexport function EmailForm({\n  email,\n  form,\n  attempts,\n  sentTo,\n  isPressed,\n  onType,\n  onSubmit,\n  onReset,\n}: EmailFormProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [fieldRef, animate] = useAnimate<HTMLDivElement>();\n  const hintId = useId();\n  const inputId = useId();\n  const isInvalid = form === 'invalid';\n  const isSent = form === 'sent';\n  const isLocked = form === 'sending' || isSent;\n  const describedBy = describedByOf(isInvalid, hintId);\n  const morphState = morphStateOf(form);\n\n  useEffect(() => {\n    const isRefusal = attempts > 0;\n    if (!isRefusal || shouldReduceMotion) {\n      return;\n    }\n    animate(fieldRef.current, NUDGE, NUDGE_TRANSITION);\n  }, [attempts, shouldReduceMotion, animate, fieldRef]);\n\n  function handleSubmit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onSubmit();\n  }\n\n  return (\n    <form\n      noValidate\n      onSubmit={handleSubmit}\n      className='@container flex flex-col gap-2'\n    >\n      <div className='flex flex-col gap-2 @md:flex-row'>\n        <div ref={fieldRef} className='min-w-0 flex-1'>\n          <label htmlFor={inputId} className='sr-only'>\n            {SECTION.emailLabel}\n          </label>\n          <Input\n            id={inputId}\n            name='email'\n            type='email'\n            size='lg'\n            autoComplete='email'\n            placeholder={SECTION.placeholder}\n            value={email}\n            readOnly={isLocked}\n            aria-invalid={isInvalid}\n            aria-describedby={describedBy}\n            onChange={(event) => onType(event.target.value)}\n          />\n        </div>\n        <MorphButton\n          type='submit'\n          size='lg'\n          state={morphState}\n          labels={LABELS}\n          idleIcon={<ArrowRightIcon />}\n          className={cn('shrink-0', pressedSolidOf(isPressed))}\n        />\n      </div>\n      <Fold open={isInvalid}>\n        <p id={hintId} className='text-destructive-ink text-xs'>\n          Enter an address like name@company.com\n        </p>\n      </Fold>\n      <Fold open={isSent}>\n        <div className='flex items-center gap-2 pt-1 text-[13px]'>\n          {isSent && <DrawnCheck tone='success' entrance='draw' />}\n          <span className='text-muted-foreground min-w-0 flex-1 truncate'>\n            We sent a sign-in link to {sentTo}\n          </span>\n          <Button\n            type='button'\n            variant='ghost'\n            size='sm'\n            onClick={onReset}\n            className='shrink-0'\n          >\n            Use another email\n          </Button>\n        </div>\n      </Fold>\n    </form>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ctas-03/email-form.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ctas/ctas-03/queue-card.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport { LoaderIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\n\nimport { QUEUE, TASKS, type QueueTask } from './data';\nimport type { TaskStatus } from './session';\n\nconst STATUS_WORD: Record<TaskStatus, string> = {\n  open: 'Open',\n  replying: 'Replying',\n  done: 'Done',\n};\n\nconst STATUS_WORDS = Object.values(STATUS_WORD);\n\nconst STATUS_RANK: Record<TaskStatus, number> = {\n  open: 0,\n  replying: 1,\n  done: 2,\n};\n\nfunction StatusGlyph({ status }: { status: TaskStatus }) {\n  if (status === 'done') {\n    return <DrawnCheck tone='success' entrance='draw' />;\n  }\n  if (status === 'replying') {\n    return <LoaderIcon className='text-muted-foreground size-4 animate-spin' />;\n  }\n  return (\n    <span className='hairline-ring ring-foreground/25 size-3.5 rounded-full' />\n  );\n}\n\nfunction dimmedOf(status: TaskStatus) {\n  if (status === 'done') {\n    return 'opacity-60';\n  }\n  return undefined;\n}\n\ntype QueueRowProps = {\n  task: QueueTask;\n  status: TaskStatus;\n};\n\nfunction QueueRow({ task, status }: QueueRowProps) {\n  const word = STATUS_WORD[status];\n\n  return (\n    <li\n      className={cn(\n        'bg-card dark:bg-foreground/[0.06] flex h-11 items-center gap-3 rounded-lg px-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-opacity duration-300 ease-(--ease-out-strong)',\n        dimmedOf(status)\n      )}\n    >\n      <span className='flex size-[18px] shrink-0 items-center justify-center'>\n        <Swap swapKey={status}>\n          <StatusGlyph status={status} />\n        </Swap>\n      </span>\n      <span className='min-w-0 flex-1 truncate text-[13px]'>\n        <span className='sr-only'>{word}: </span>\n        {task.title}\n      </span>\n      <span\n        aria-hidden='true'\n        className='text-muted-foreground w-14 shrink-0 text-end text-xs'\n      >\n        <WordRoll\n          text={word}\n          labels={STATUS_WORDS}\n          value={STATUS_RANK[status]}\n        />\n      </span>\n    </li>\n  );\n}\n\ntype QueueCardProps = {\n  tasks: TaskStatus[];\n  resolved: number;\n};\n\nexport function QueueCard({ tasks, resolved }: QueueCardProps) {\n  return (\n    <div className='bg-foreground/[0.04] flex flex-col gap-3 rounded-xl p-3'>\n      <div className='flex items-center justify-between gap-3 px-1'>\n        <div className='flex min-w-0 items-center gap-2'>\n          <h3 className='text-sm font-medium'>{QUEUE.title}</h3>\n          <Badge variant='secondary'>{QUEUE.badge}</Badge>\n        </div>\n        <p className='text-muted-foreground flex shrink-0 items-baseline gap-1 text-xs tabular-nums'>\n          <MotionNumber value={resolved} />\n          <span>of {TASKS.length} done</span>\n        </p>\n      </div>\n      <ul aria-label='Conversations waiting' className='flex flex-col gap-1.5'>\n        {TASKS.map((task, index) => (\n          <QueueRow key={task.id} task={task} status={tasks[index]} />\n        ))}\n      </ul>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ctas-03/queue-card.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ctas/ctas-03/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\n\nimport { TASKS } from './data';\n\nexport type TaskStatus = 'open' | 'replying' | 'done';\n\nexport type FormStatus = 'idle' | 'invalid' | 'sending' | 'sent';\n\nexport type CtaState = {\n  email: string;\n  form: FormStatus;\n  /** Counts the refused submits, so a second refusal nudges the field again. */\n  attempts: number;\n  sentTo: string;\n  tasks: TaskStatus[];\n};\n\nexport type CtaAction =\n  | { type: 'typed'; value: string }\n  | { type: 'submitted' }\n  | { type: 'sent' }\n  | { type: 'reset' }\n  | { type: 'replying'; index: number }\n  | { type: 'resolved'; index: number };\n\ntype Step = SessionStep<CtaState, CtaAction>;\n\nconst EMAIL_SHAPE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nexport function isEmailLike(email: string) {\n  return EMAIL_SHAPE.test(email.trim());\n}\n\nfunction allTasks(status: TaskStatus): TaskStatus[] {\n  return TASKS.map(() => status);\n}\n\nexport const INITIAL: CtaState = {\n  email: '',\n  form: 'idle',\n  attempts: 0,\n  sentTo: '',\n  tasks: allTasks('open'),\n};\n\nfunction submitted(state: CtaState): CtaState {\n  const isIdle = state.form === 'idle';\n  const isRefused = state.form === 'invalid';\n  const canSubmit = isIdle || isRefused;\n  if (!canSubmit) {\n    return state;\n  }\n  if (!isEmailLike(state.email)) {\n    return { ...state, form: 'invalid', attempts: state.attempts + 1 };\n  }\n  return { ...state, form: 'sending' };\n}\n\nfunction sent(state: CtaState): CtaState {\n  if (state.form !== 'sending') {\n    return state;\n  }\n  return { ...state, form: 'sent', sentTo: state.email.trim() };\n}\n\nfunction withTask(\n  state: CtaState,\n  index: number,\n  status: TaskStatus\n): CtaState {\n  const tasks = state.tasks.map((current, position) => {\n    if (position === index) {\n      return status;\n    }\n    return current;\n  });\n  return { ...state, tasks };\n}\n\nexport function reducer(state: CtaState, action: CtaAction): CtaState {\n  switch (action.type) {\n    case 'typed':\n      return { ...state, email: action.value, form: 'idle' };\n    case 'submitted':\n      return submitted(state);\n    case 'sent':\n      return sent(state);\n    case 'reset':\n      return { ...state, email: '', form: 'idle' };\n    case 'replying':\n      return withTask(state, action.index, 'replying');\n    case 'resolved':\n      return withTask(state, action.index, 'done');\n  }\n}\n\nexport function resolvedCountOf(state: CtaState) {\n  const resolved = state.tasks.filter((status) => status === 'done');\n  return resolved.length;\n}\n\nconst TYPED_EMAIL = 'amina@lubumbashi-books.example';\n\nconst KEY_MS = 48;\n\nexport const SEND_MS = 1100;\n\nfunction typing(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((value, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'typed', value },\n  }));\n}\n\nfunction replying(after: number, index: number): Step {\n  return { after, action: { type: 'replying', index } };\n}\n\nfunction resolved(after: number, index: number): Step {\n  return { after, action: { type: 'resolved', index } };\n}\n\n/**\n * The queue clears on its own clock. Someone types an address and asks for the link while the\n * second conversation is being answered, and the rest of the queue goes on after the link is sent.\n */\nexport const SCRIPT: Step[] = [\n  replying(1200, 0),\n  resolved(1300, 0),\n  replying(600, 1),\n  ...typing(TYPED_EMAIL, 500),\n  resolved(500, 1),\n  {\n    after: 900,\n    by: 'demo',\n    press: 'submit',\n    action: { type: 'submitted' },\n  },\n  replying(1500, 2),\n  resolved(1300, 2),\n  replying(700, 3),\n  resolved(1200, 3),\n  replying(700, 4),\n  resolved(1200, 4),\n];\n\n/** Under reduced motion the address is typed and the whole queue is cleared. */\nexport const RESTING: CtaState = {\n  ...INITIAL,\n  email: TYPED_EMAIL,\n  tasks: allTasks('done'),\n};\n\nexport const LOOP_AFTER_MS = 3600;\n",
      "type": "registry:component",
      "target": "components/blocks/ctas-03/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/ctas/ctas-03/data.ts",
      "content": "export type QueueTask = {\n  id: string;\n  title: string;\n};\n\nexport const SECTION = {\n  title: 'Start Monday with an empty queue',\n  description:\n    'Use your work email and Ferrywell sorts the conversations already waiting in your inbox. What it can answer lands in Done before you open the first one.',\n  placeholder: 'you@company.com',\n  emailLabel: 'Work email',\n};\n\nexport const QUEUE = {\n  title: 'Support queue',\n  badge: 'Sample queue',\n};\n\nexport const TASKS: QueueTask[] = [\n  { id: 'refund', title: 'Refund for order 4821' },\n  { id: 'password', title: 'Password reset for the Lubumbashi office' },\n  { id: 'invoice', title: 'Invoice copy for March' },\n  { id: 'delivery', title: 'Delivery to Goma is a day late' },\n  { id: 'limits', title: 'Question about the API limits' },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/ctas-03/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "ctas"
  ],
  "type": "registry:block"
}