{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-product-05",
  "title": "Before and after in one bar",
  "description": "One bar that shows how a week splits between busywork and judgment: the caption lights word by word and the blocks flip one after another while two percentages tick across, on its own when it enters the screen or following a progress value.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-05/index.tsx",
      "content": "import { WorkSplit } from './work-split';\n\nexport default function AiProduct05() {\n  return <WorkSplit />;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-05/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-05/work-split.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { useAutoplay } from '@/registry/ndeko/hooks/use-autoplay';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { UsersRoundIcon } 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 { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport {\n  BLOCK_SHARE,\n  BLOCKS,\n  BUSYWORK_AFTER,\n  BUSYWORK_BEFORE,\n  CAPTION_WORDS,\n  flipRankOf,\n  FLIP_COUNT,\n  FLIPS_START,\n  SECTION,\n  WORDS_END,\n} from './data';\n\nconst TICK_COUNT = 40;\n\nconst TICK_MS = 110;\n\nconst FIRST_TICK_MS = 1000;\n\nconst LOOP_AFTER_MS = 3800;\n\n/** A share that lands on a whole block, such as 0.3 times 10, must not fall to the block before. */\nconst ROUNDING_GUARD = 0.0001;\n\nfunction clamped(value: number) {\n  const atLeastNone = Math.max(0, value);\n  return Math.min(1, atLeastNone);\n}\n\nfunction tickAfterOf(index: number) {\n  if (index === 0) {\n    return FIRST_TICK_MS;\n  }\n  return TICK_MS;\n}\n\nconst TICK_VALUES = Array.from({ length: TICK_COUNT }, (_, index) => index + 1);\n\nfunction litWordsOf(progress: number) {\n  const share = clamped(progress / WORDS_END);\n  const words = share * CAPTION_WORDS.length;\n  return Math.round(words);\n}\n\nfunction flippedOf(progress: number) {\n  const span = 1 - FLIPS_START;\n  const sinceStart = progress - FLIPS_START;\n  const share = clamped(sinceStart / span);\n  const blocks = share * FLIP_COUNT;\n  return Math.floor(blocks + ROUNDING_GUARD);\n}\n\nfunction isJudgment(blockIndex: number, flipped: number) {\n  if (blockIndex >= BUSYWORK_BEFORE) {\n    return true;\n  }\n  const rank = flipRankOf(blockIndex);\n  if (rank === null) {\n    return false;\n  }\n  return rank < flipped;\n}\n\nfunction blockToneOf(isJudgmentBlock: boolean) {\n  if (isJudgmentBlock) {\n    return 'bg-primary scale-y-100';\n  }\n  return 'bg-foreground/[0.16] scale-y-[0.7]';\n}\n\nfunction wordToneOf(isLit: boolean) {\n  if (isLit) {\n    return 'text-foreground';\n  }\n  return 'text-foreground/25';\n}\n\nfunction phaseOf(flipped: number) {\n  if (flipped === 0) {\n    return 'Before the agent';\n  }\n  if (flipped >= FLIP_COUNT) {\n    return 'With the agent';\n  }\n  return 'The agent takes over';\n}\n\nfunction percentLabel(blocks: number) {\n  const share = blocks * BLOCK_SHARE;\n  const percent = Math.round(share);\n  return `${percent}%`;\n}\n\n/** The position drawn: the one given, the step the demonstration is on, or the end once a person takes over. */\nfunction shownOf(\n  progress: number | undefined,\n  isAutoplaying: boolean,\n  tick: number\n) {\n  if (progress !== undefined) {\n    return clamped(progress);\n  }\n  if (isAutoplaying) {\n    return tick / TICK_COUNT;\n  }\n  return 1;\n}\n\nexport type WorkSplitProps = {\n  /**\n   * A position between 0 and 1, from a scroll or a slider. Without it the story plays by itself\n   * while it is on screen.\n   */\n  progress?: number;\n  className?: string;\n};\n\nexport function WorkSplit({ progress, className }: WorkSplitProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [tick, setTick] = useState(0);\n  const isControlled = progress !== undefined;\n  const steps = TICK_VALUES.map((value, index) => ({\n    after: tickAfterOf(index),\n    run: () => setTick(value),\n  }));\n  const { ref, isAutoplaying, restart } = useAutoplay<HTMLElement>(steps, {\n    loopAfter: LOOP_AFTER_MS,\n    onReset: () => setTick(0),\n    isEnabled: !isControlled,\n  });\n  const shown = shownOf(progress, isAutoplaying, tick);\n  const litWords = litWordsOf(shown);\n  const flipped = flippedOf(shown);\n  const busyBlocks = BUSYWORK_BEFORE - flipped;\n  const judgmentBlocks = BLOCKS.length - busyBlocks;\n  const phase = phaseOf(flipped);\n  const playsItself = !isControlled;\n  const hasEnded = !isAutoplaying;\n  const canPlay = !shouldReduceMotion;\n  const canReplay = playsItself && hasEnded && canPlay;\n  const beforeShare = percentLabel(BUSYWORK_BEFORE);\n  const afterShare = percentLabel(BUSYWORK_AFTER);\n  const summary = `Before the agent, ${beforeShare} of the week is busywork. With the agent, ${afterShare}.`;\n\n  return (\n    <section ref={ref} className={cn('@container', className)}>\n      <div className='mx-auto flex max-w-4xl flex-col gap-8 px-4 py-16 @2xl:px-6 @2xl:py-24'>\n        <div className='flex flex-wrap items-center justify-between gap-x-4 gap-y-2'>\n          <p className='text-primary-ink flex items-center gap-1.5 text-[13px] font-medium'>\n            <UsersRoundIcon className='size-4' />\n            {SECTION.label}\n          </p>\n          <div className='flex items-center gap-2'>\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Replay'\n            />\n            <Badge variant='secondary'>Illustrative</Badge>\n          </div>\n        </div>\n        <p className='text-xl font-semibold text-balance @2xl:text-3xl'>\n          {CAPTION_WORDS.map((word, index) => (\n            <span\n              key={index}\n              className={cn(\n                'transition-colors duration-300 ease-(--ease-out-strong)',\n                wordToneOf(index < litWords)\n              )}\n            >\n              {word}{' '}\n            </span>\n          ))}\n        </p>\n        <div className='flex flex-col gap-3'>\n          <p className='text-muted-foreground text-[13px]'>\n            <Swap swapKey={phase}>{phase}</Swap>\n          </p>\n          <div role='img' aria-label={summary} className='flex h-12 gap-[3px]'>\n            {BLOCKS.map((blockIndex) => (\n              <span\n                key={blockIndex}\n                aria-hidden='true'\n                className={cn(\n                  'flex-1 origin-bottom rounded-[3px] transition-[background-color,scale] duration-300 ease-(--ease-out-strong)',\n                  blockToneOf(isJudgment(blockIndex, flipped))\n                )}\n              />\n            ))}\n          </div>\n          <dl className='grid grid-cols-2 gap-4 text-[13px]'>\n            <div className='flex flex-col gap-0.5'>\n              <dt className='text-muted-foreground flex items-center gap-2'>\n                <span className='bg-foreground/[0.16] size-2 rounded-[2px]' />\n                Busywork\n              </dt>\n              <dd className='w-12 text-2xl font-semibold tabular-nums'>\n                {percentLabel(busyBlocks)}\n              </dd>\n            </div>\n            <div className='flex flex-col items-end gap-0.5 text-end'>\n              <dt className='text-muted-foreground flex items-center gap-2'>\n                Judgment\n                <span className='bg-primary size-2 rounded-[2px]' />\n              </dt>\n              <dd className='w-12 text-2xl font-semibold tabular-nums'>\n                {percentLabel(judgmentBlocks)}\n              </dd>\n            </div>\n          </dl>\n          <p className='text-muted-foreground text-xs'>{SECTION.note}</p>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-05/work-split.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-05/data.ts",
      "content": "export const SECTION = {\n  label: 'Before and after',\n  caption:\n    'Most of a support week went to busywork: copying figures, chasing replies, filing the same note twice. Now an agent drafts it, and the week goes to judgment.',\n  note: 'Illustrative split of one team week',\n};\n\nexport const BLOCK_COUNT = 25;\n\nexport const BLOCK_SHARE = 100 / BLOCK_COUNT;\n\nexport const BUSYWORK_BEFORE = 18;\n\nexport const BUSYWORK_AFTER = 5;\n\nexport const FLIP_COUNT = BUSYWORK_BEFORE - BUSYWORK_AFTER;\n\n/** The blocks flip from the edge of the judgment side toward the left, one after another. */\nexport function flipRankOf(blockIndex: number) {\n  const isBeforeBusywork = blockIndex < BUSYWORK_BEFORE;\n  const isKept = blockIndex < BUSYWORK_AFTER;\n  if (!isBeforeBusywork || isKept) {\n    return null;\n  }\n  return BUSYWORK_BEFORE - 1 - blockIndex;\n}\n\nexport const BLOCKS = Array.from({ length: BLOCK_COUNT }, (_, index) => index);\n\nexport const CAPTION_WORDS = SECTION.caption.split(' ');\n\n/** The words light during the first part of the story, the blocks flip during the rest. */\nexport const WORDS_END = 0.55;\n\nexport const FLIPS_START = 0.3;\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-05/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "ai-product"
  ],
  "type": "registry:block"
}