{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-product-03",
  "title": "Leads an agent enriches",
  "description": "A leads table with sorting, search, status and owner filters, selection and pages, while an agent works down it: a row lights, a cell shimmers as its value is fetched, then the value settles into place and the count of enriched leads rolls.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/avatar.json",
    "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/checkbox.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/pagination.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/select-native.json",
    "https://ui.ndekocode.dev/r/table.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"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-03/index.tsx",
      "content": "'use client';\n\nimport { useCallback } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { ChevronLeftIcon, ChevronRightIcon } from '@/registry/ndeko/lib/icons';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport {\n  Pagination,\n  PaginationContent,\n  PaginationItem,\n} from '@/registry/ndeko/ui/pagination';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { AGENT, leadOf, PASS_IDS } from './data';\nimport { LeadsTable } from './leads-table';\nimport {\n  enrichedCountOf,\n  INITIAL,\n  LOOP_AFTER_MS,\n  pageCountOf,\n  pageRowsOf,\n  PAGE_SIZE,\n  reducer,\n  RESTING,\n  resultOf,\n  SCRIPT,\n  TOTAL,\n  type LeadsAction,\n  type LeadsState,\n} from './session';\nimport { Toolbar } from './toolbar';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nfunction rangeLineOf(page: number, shown: number, total: number) {\n  if (total === 0) {\n    return 'No lead';\n  }\n  const offset = page * PAGE_SIZE;\n  const first = offset + 1;\n  const lastOffset = shown - 1;\n  const last = first + lastOffset;\n  return `${first} to ${last} of ${total}`;\n}\n\nfunction leadsWordOf(count: number) {\n  if (count === 1) {\n    return 'lead';\n  }\n  return 'leads';\n}\n\nfunction passLineOf(state: LeadsState, enriched: number) {\n  if (state.litId !== null) {\n    const lead = leadOf(state.litId);\n    const name = lead?.name ?? 'a lead';\n    return `Working on ${name}`;\n  }\n  if (enriched === 0) {\n    return 'Ready to start';\n  }\n  if (enriched >= PASS_IDS.length) {\n    return 'Pass finished';\n  }\n  return 'Moving to the next lead';\n}\n\nexport default function AiProduct03() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    isFinished,\n    restart,\n    pressed,\n  } = useSession(SESSION);\n  useKeptHeight(ref);\n  const result = resultOf(state);\n  const rows = pageRowsOf(result, state.page);\n  const total = result.length;\n  const pageCount = pageCountOf(total);\n  const pageNumber = state.page + 1;\n  const isFirstPage = state.page === 0;\n  const isLastPage = pageNumber >= pageCount;\n  const rangeLine = rangeLineOf(state.page, rows.length, total);\n  const enriched = enrichedCountOf(state);\n  const passLine = passLineOf(state, enriched);\n  const selectedCount = state.selected.length;\n  const message = spokenUnless(isAutoplaying, state.spoken);\n  const canReplay = isFinished && !isAutoplaying;\n\n  const focusLater = useCallback(\n    (selector: string) => {\n      requestAnimationFrame(() => {\n        const target = ref.current?.querySelector<HTMLElement>(selector);\n        target?.focus();\n      });\n    },\n    [ref]\n  );\n\n  /** The button of the empty state leaves with it, so the focus goes back to the search field. */\n  function actOnTable(action: LeadsAction) {\n    act(action);\n    if (action.type === 'filtersCleared') {\n      focusLater('[data-leads-search]');\n    }\n  }\n\n  function clearSelection() {\n    act({ type: 'selectionCleared' });\n    focusLater('[data-select-page]');\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container min-h-[52rem] w-full @3xl:min-h-[46rem]'\n      >\n        <div className='mx-auto flex max-w-6xl flex-col gap-4 p-4 @3xl:p-8'>\n          <header className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n            <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n              <h2 className='text-lg font-semibold text-balance'>Leads</h2>\n              <p className='text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-xs'>\n                <span className='flex items-baseline gap-1'>\n                  <MotionNumber value={total} />\n                  {leadsWordOf(total)}\n                </span>\n                <Badge variant='secondary'>Illustrative</Badge>\n              </p>\n            </div>\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Replay'\n            />\n          </header>\n\n          <section\n            aria-label='Agent pass'\n            className='bg-foreground/[0.04] flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg px-3 py-2'\n          >\n            <MeshTile\n              seed={AGENT.name}\n              color={seriesColorOf(AGENT.series)}\n              size='md'\n            />\n            <p className='flex items-baseline gap-1 text-[13px]'>\n              {AGENT.name} enriched\n              <MotionNumber value={enriched} className='font-medium' />\n              of {TOTAL} leads\n            </p>\n            <span className='text-muted-foreground ms-auto text-xs'>\n              <Swap swapKey={passLine}>{passLine}</Swap>\n            </span>\n          </section>\n\n          <Toolbar\n            query={state.query}\n            status={state.status}\n            owner={state.owner}\n            onQuery={(text) => act({ type: 'queryTyped', text })}\n            onStatus={(status) => act({ type: 'statusPicked', status })}\n            onOwner={(owner) => act({ type: 'ownerPicked', owner })}\n          />\n\n          <Fold open={selectedCount > 0}>\n            <div className='flex items-center gap-2 text-[13px]'>\n              <span className='tabular-nums'>{selectedCount} selected</span>\n              <Button\n                type='button'\n                variant='ghost'\n                size='sm'\n                onClick={clearSelection}\n                className='text-muted-foreground'\n              >\n                Clear selection\n              </Button>\n            </div>\n          </Fold>\n\n          <div className='bg-card hairline-ring ring-border @container min-h-[26.5rem] overflow-hidden rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n            <LeadsTable\n              rows={rows}\n              state={state}\n              isActive={isInView}\n              pressed={pressed}\n              onAction={actOnTable}\n            />\n          </div>\n\n          <Pagination className='items-center justify-between gap-3'>\n            <p className='text-muted-foreground text-xs tabular-nums'>\n              {rangeLine}\n            </p>\n            <PaginationContent>\n              <PaginationItem>\n                <Button\n                  type='button'\n                  variant='outline'\n                  size='icon-sm'\n                  aria-label='Go to the previous page'\n                  disabled={isFirstPage}\n                  focusableWhenDisabled\n                  onClick={() =>\n                    act({ type: 'pageTurned', page: state.page - 1 })\n                  }\n                >\n                  <ChevronLeftIcon />\n                </Button>\n              </PaginationItem>\n              <PaginationItem>\n                <p className='text-muted-foreground px-1 text-xs tabular-nums'>\n                  Page {pageNumber} of {pageCount}\n                </p>\n              </PaginationItem>\n              <PaginationItem>\n                <Button\n                  type='button'\n                  variant='outline'\n                  size='icon-sm'\n                  aria-label='Go to the next page'\n                  disabled={isLastPage}\n                  focusableWhenDisabled\n                  onClick={() =>\n                    act({ type: 'pageTurned', page: state.page + 1 })\n                  }\n                >\n                  <ChevronRightIcon />\n                </Button>\n              </PaginationItem>\n            </PaginationContent>\n          </Pagination>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-03/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-03/leads-table.tsx",
      "content": "'use client';\n\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Checkbox } from '@/registry/ndeko/ui/checkbox';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHead,\n  TableHeader,\n  TableRow,\n} from '@/registry/ndeko/ui/table';\n\nimport { LandedValue, ShimmerBar } from './cell-states';\nimport { ownerOf, STATUS_LABEL, type Lead, type LeadStatus } from './data';\nimport {\n  cellKeyOf,\n  isLanded,\n  type Field,\n  type LeadsAction,\n  type LeadsState,\n  type Sort,\n  type SortColumn,\n  type SortDirection,\n} from './session';\n\nconst COLUMN_COUNT = 8;\n\nconst STATUS_VARIANT: Record<LeadStatus, 'secondary' | 'info' | 'success'> = {\n  new: 'secondary',\n  contacted: 'info',\n  qualified: 'success',\n};\n\nconst SORT_BUTTON =\n  'group/sort focus-visible:ring-ring/25 hover:bg-foreground/[0.05] hover:text-foreground -mx-1.5 inline-flex h-7 cursor-pointer items-center gap-1 rounded-md px-1.5 transition-[background-color,color,scale] duration-150 outline-none focus-visible:ring-[3px]';\n\nconst FRAME_WIDE = 'sticky left-0 w-[100cqw]';\n\nconst SORT_LABEL: Record<SortColumn, string> = {\n  name: 'Lead',\n  company: 'Company',\n  status: 'Status',\n  size: 'Employees',\n};\n\nfunction ariaSortOf(isSorted: boolean, direction: SortDirection) {\n  if (!isSorted) {\n    return 'none';\n  }\n  if (direction === 'asc') {\n    return 'ascending';\n  }\n  return 'descending';\n}\n\nfunction arrowClassOf(isSorted: boolean, direction: SortDirection) {\n  if (!isSorted) {\n    return 'opacity-0 group-hover/sort:opacity-40 group-focus-visible/sort:opacity-40';\n  }\n  if (direction === 'asc') {\n    return 'opacity-100';\n  }\n  return 'rotate-180 opacity-100';\n}\n\ntype SortHeadProps = {\n  column: SortColumn;\n  sort: Sort | null;\n  isFigure?: boolean;\n  onSort: (column: SortColumn) => void;\n};\n\nfunction SortHead({ column, sort, isFigure = false, onSort }: SortHeadProps) {\n  const isSorted = sort?.column === column;\n  const direction = sort?.direction ?? 'asc';\n\n  return (\n    <TableHead\n      aria-sort={ariaSortOf(isSorted, direction)}\n      className={cn(isFigure && 'text-end')}\n    >\n      <button\n        type='button'\n        onClick={() => onSort(column)}\n        className={cn(SORT_BUTTON, isFigure && 'flex-row-reverse')}\n      >\n        {SORT_LABEL[column]}\n        <ArrowUpIcon\n          aria-hidden='true'\n          className={cn(\n            'size-3.5 transition-[opacity,rotate] duration-200 ease-(--ease-out-strong)',\n            arrowClassOf(isSorted, direction)\n          )}\n        />\n      </button>\n    </TableHead>\n  );\n}\n\ntype CellPhase = 'empty' | 'fetching' | 'landed';\n\nfunction phaseOf(state: LeadsState, id: string, field: Field): CellPhase {\n  if (isLanded(state, id, field)) {\n    return 'landed';\n  }\n  const filling = state.filling;\n  if (filling === null) {\n    return 'empty';\n  }\n  const isThisLead = filling.id === id;\n  const isThisField = filling.field === field;\n  if (isThisLead && isThisField) {\n    return 'fetching';\n  }\n  return 'empty';\n}\n\ntype EnrichedCellProps = {\n  phase: CellPhase;\n  isLanding: boolean;\n  isActive: boolean;\n  shimmerClassName: string;\n  label: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\nfunction EnrichedCell({\n  phase,\n  isLanding,\n  isActive,\n  shimmerClassName,\n  label,\n  className,\n  children,\n}: EnrichedCellProps) {\n  return (\n    <TableCell className={cn('py-0', className)}>\n      {phase === 'landed' && (\n        <LandedValue isLanding={isLanding}>{children}</LandedValue>\n      )}\n      {phase === 'fetching' && (\n        <>\n          <ShimmerBar isActive={isActive} className={shimmerClassName} />\n          <span className='sr-only'>Fetching {label}</span>\n        </>\n      )}\n      {phase === 'empty' && (\n        <>\n          <span aria-hidden='true' className='text-muted-foreground/60'>\n            -\n          </span>\n          <span className='sr-only'>Not enriched yet</span>\n        </>\n      )}\n    </TableCell>\n  );\n}\n\nfunction selectedStateOf(isSelected: boolean) {\n  if (isSelected) {\n    return 'selected';\n  }\n  return undefined;\n}\n\ntype LeadRowProps = {\n  lead: Lead;\n  state: LeadsState;\n  isActive: boolean;\n  pressed: string | null;\n  onAction: (action: LeadsAction) => void;\n};\n\nfunction LeadRow({ lead, state, isActive, pressed, onAction }: LeadRowProps) {\n  const owner = ownerOf(lead.owner);\n  const isSelected = state.selected.includes(lead.id);\n  const isLit = state.litId === lead.id;\n  const emailKey = cellKeyOf(lead.id, 'email');\n  const sizeKey = cellKeyOf(lead.id, 'size');\n  const isSelectPressed = pressed === `select-${lead.id}`;\n\n  return (\n    <TableRow\n      data-state={selectedStateOf(isSelected)}\n      data-lit={isLit}\n      className='data-[lit=true]:bg-info/10 h-12'\n    >\n      <TableCell className='py-0'>\n        <Checkbox\n          checked={isSelected}\n          aria-label={`Select ${lead.name}`}\n          onCheckedChange={() => onAction({ type: 'rowToggled', id: lead.id })}\n          className={cn(\n            'transition-[background-color,box-shadow,scale]',\n            pressedQuietOf(isSelectPressed)\n          )}\n        />\n      </TableCell>\n      <TableCell className='py-0'>\n        <span className='flex items-center gap-2.5 whitespace-nowrap'>\n          <Avatar seed={lead.name} className='size-6' />\n          <span className='font-medium'>{lead.name}</span>\n        </span>\n      </TableCell>\n      <TableCell className='py-0'>\n        <span className='flex items-center gap-2 whitespace-nowrap'>\n          <CompanyMark seed={lead.company} />\n          {lead.company}\n        </span>\n      </TableCell>\n      <TableCell className='py-0'>\n        <Badge variant={STATUS_VARIANT[lead.status]}>\n          {STATUS_LABEL[lead.status]}\n        </Badge>\n      </TableCell>\n      <TableCell className='py-0'>\n        <span className='flex items-center gap-2 whitespace-nowrap'>\n          <Avatar seed={owner.name} className='size-5' />\n          {owner.firstName}\n        </span>\n      </TableCell>\n      <TableCell className='text-muted-foreground py-0 whitespace-nowrap'>\n        {lead.city}\n      </TableCell>\n      <EnrichedCell\n        phase={phaseOf(state, lead.id, 'email')}\n        isLanding={state.settling === emailKey}\n        isActive={isActive}\n        shimmerClassName='w-40'\n        label='the work email'\n        className='min-w-56'\n      >\n        <span className='whitespace-nowrap'>{lead.email}</span>\n      </EnrichedCell>\n      <EnrichedCell\n        phase={phaseOf(state, lead.id, 'size')}\n        isLanding={state.settling === sizeKey}\n        isActive={isActive}\n        shimmerClassName='ms-auto w-8'\n        label='the number of employees'\n        className='text-end tabular-nums'\n      >\n        {lead.employees}\n      </EnrichedCell>\n    </TableRow>\n  );\n}\n\ntype SelectPageBoxProps = {\n  rowIds: string[];\n  selected: string[];\n  onAction: (action: LeadsAction) => void;\n};\n\nfunction SelectPageBox({ rowIds, selected, onAction }: SelectPageBoxProps) {\n  const selectedOnPage = rowIds.filter((id) => selected.includes(id));\n  const hasRows = rowIds.length > 0;\n  const isPageSelected = hasRows && selectedOnPage.length === rowIds.length;\n  const isPartlySelected = selectedOnPage.length > 0 && !isPageSelected;\n\n  return (\n    <Checkbox\n      data-select-page\n      checked={isPageSelected}\n      indeterminate={isPartlySelected}\n      disabled={!hasRows}\n      aria-label='Select the leads of this page'\n      onCheckedChange={() => onAction({ type: 'pageToggled' })}\n    />\n  );\n}\n\ntype LeadsTableProps = {\n  rows: Lead[];\n  state: LeadsState;\n  isActive: boolean;\n  pressed: string | null;\n  onAction: (action: LeadsAction) => void;\n};\n\nexport function LeadsTable({\n  rows,\n  state,\n  isActive,\n  pressed,\n  onAction,\n}: LeadsTableProps) {\n  const rowIds = rows.map((lead) => lead.id);\n  const isEmpty = rows.length === 0;\n\n  function sortBy(column: SortColumn) {\n    onAction({ type: 'sorted', column });\n  }\n\n  return (\n    <Table className='min-w-[56rem]'>\n      <caption className='sr-only'>Leads</caption>\n      <TableHeader>\n        <TableRow className='hover:bg-transparent'>\n          <TableHead>\n            <SelectPageBox\n              rowIds={rowIds}\n              selected={state.selected}\n              onAction={onAction}\n            />\n          </TableHead>\n          <SortHead column='name' sort={state.sort} onSort={sortBy} />\n          <SortHead column='company' sort={state.sort} onSort={sortBy} />\n          <SortHead column='status' sort={state.sort} onSort={sortBy} />\n          <TableHead>Owner</TableHead>\n          <TableHead>City</TableHead>\n          <TableHead>Work email</TableHead>\n          <SortHead column='size' sort={state.sort} isFigure onSort={sortBy} />\n        </TableRow>\n      </TableHeader>\n      <TableBody>\n        {rows.map((lead) => (\n          <LeadRow\n            key={lead.id}\n            lead={lead}\n            state={state}\n            isActive={isActive}\n            pressed={pressed}\n            onAction={onAction}\n          />\n        ))}\n        {isEmpty && (\n          <TableRow className='hover:bg-transparent'>\n            <TableCell colSpan={COLUMN_COUNT} className='p-0'>\n              <div\n                className={cn(\n                  FRAME_WIDE,\n                  'flex flex-col items-start gap-3 p-4'\n                )}\n              >\n                <p className='text-muted-foreground text-[13px]'>\n                  No lead matches these filters\n                </p>\n                <Button\n                  type='button'\n                  variant='outline'\n                  size='sm'\n                  onClick={() => onAction({ type: 'filtersCleared' })}\n                >\n                  Remove the filters\n                </Button>\n              </div>\n            </TableCell>\n          </TableRow>\n        )}\n      </TableBody>\n    </Table>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-03/leads-table.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-03/toolbar.tsx",
      "content": "'use client';\n\nimport { SearchIcon } from '@/registry/ndeko/lib/icons';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { SelectNative } from '@/registry/ndeko/ui/select-native';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport { OWNERS, STATUS_LABEL } from './data';\nimport type { OwnerFilter, StatusFilter } from './session';\n\nconst STATUS_SEGMENTS: Segment<StatusFilter>[] = [\n  { value: 'all', label: 'All' },\n  { value: 'new', label: STATUS_LABEL.new },\n  { value: 'contacted', label: STATUS_LABEL.contacted },\n  { value: 'qualified', label: STATUS_LABEL.qualified },\n];\n\nfunction ownerFilterOf(value: string): OwnerFilter | null {\n  if (value === 'all') {\n    return 'all';\n  }\n  const owner = OWNERS.find((candidate) => candidate.id === value);\n  if (owner) {\n    return owner.id;\n  }\n  return null;\n}\n\ntype ToolbarProps = {\n  query: string;\n  status: StatusFilter;\n  owner: OwnerFilter;\n  onQuery: (text: string) => void;\n  onStatus: (status: StatusFilter) => void;\n  onOwner: (owner: OwnerFilter) => void;\n};\n\nexport function Toolbar({\n  query,\n  status,\n  owner,\n  onQuery,\n  onStatus,\n  onOwner,\n}: ToolbarProps) {\n  function pickOwner(event: React.ChangeEvent<HTMLSelectElement>) {\n    const picked = ownerFilterOf(event.target.value);\n    if (picked) {\n      onOwner(picked);\n    }\n  }\n\n  return (\n    <div className='flex flex-wrap items-center gap-2'>\n      <div className='relative min-w-44 flex-1'>\n        <SearchIcon className='text-muted-foreground pointer-events-none absolute start-2.5 top-1/2 size-4 -translate-y-1/2' />\n        <Input\n          type='search'\n          aria-label='Search leads'\n          data-leads-search\n          autoComplete='off'\n          placeholder='Search name, company or city'\n          value={query}\n          onChange={(event) => onQuery(event.target.value)}\n          className='ps-8'\n        />\n      </div>\n      <Segments\n        label='Status'\n        value={status}\n        segments={STATUS_SEGMENTS}\n        onValueChange={onStatus}\n      />\n      <SelectNative\n        aria-label='Owner'\n        value={owner}\n        onChange={pickOwner}\n        className='w-36'\n      >\n        <option value='all'>All owners</option>\n        {OWNERS.map((candidate) => (\n          <option key={candidate.id} value={candidate.id}>\n            {candidate.name}\n          </option>\n        ))}\n      </SelectNative>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-03/toolbar.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-03/cell-states.tsx",
      "content": "'use client';\n\nimport { motion } from 'motion/react';\nimport { useEffect, useRef } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { EASE_OUT_STRONG, FADE } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst SWEEP_MS = 1100;\n\ntype ShimmerBarProps = {\n  /** False off screen: the band stops where it is. */\n  isActive: boolean;\n  className?: string;\n};\n\nexport function ShimmerBar({ isActive, className }: ShimmerBarProps) {\n  const bandRef = useRef<HTMLSpanElement>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  useEffect(() => {\n    const band = bandRef.current;\n    if (!band || shouldReduceMotion || !isActive) {\n      return;\n    }\n    const sweep = [\n      { transform: 'translateX(-100%)' },\n      { transform: 'translateX(200%)' },\n    ];\n    const animation = band.animate(sweep, {\n      duration: SWEEP_MS,\n      iterations: Infinity,\n      easing: 'linear',\n    });\n    return () => animation.cancel();\n  }, [isActive, shouldReduceMotion]);\n\n  return (\n    <span\n      aria-hidden='true'\n      className={cn(\n        'bg-foreground/[0.07] relative block h-3 overflow-hidden rounded-full',\n        className\n      )}\n    >\n      <span\n        ref={bandRef}\n        className='via-foreground/10 absolute inset-y-0 start-0 w-1/2 bg-linear-to-r from-transparent to-transparent'\n      />\n    </span>\n  );\n}\n\nfunction landingFrom(isLanding: boolean, shouldReduceMotion: boolean) {\n  if (!isLanding) {\n    return false;\n  }\n  if (shouldReduceMotion) {\n    return { opacity: 0 };\n  }\n  return { opacity: 0, scale: 1.04 };\n}\n\nconst SETTLE = { duration: 0.28, ease: EASE_OUT_STRONG };\n\nfunction landTransitionOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return FADE;\n  }\n  return SETTLE;\n}\n\ntype LandedValueProps = {\n  /** True for the value that has just arrived: it settles from 1.04. A value that was there already is simply drawn. */\n  isLanding: boolean;\n  className?: string;\n  children: React.ReactNode;\n};\n\nexport function LandedValue({\n  isLanding,\n  className,\n  children,\n}: LandedValueProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const initial = landingFrom(isLanding, shouldReduceMotion);\n  const transition = landTransitionOf(shouldReduceMotion);\n\n  return (\n    <motion.span\n      initial={initial}\n      animate={{ opacity: 1, scale: 1 }}\n      transition={transition}\n      className={cn('inline-block origin-left', className)}\n    >\n      {children}\n    </motion.span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-03/cell-states.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-03/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport {\n  AGENT,\n  LEADS,\n  leadOf,\n  PASS_IDS,\n  STATUS_ORDER,\n  type Lead,\n  type LeadStatus,\n  type OwnerId,\n} from './data';\n\nexport type Field = 'email' | 'size';\n\nexport type SortColumn = 'name' | 'company' | 'status' | 'size';\n\nexport type SortDirection = 'asc' | 'desc';\n\nexport type Sort = { column: SortColumn; direction: SortDirection };\n\nexport type StatusFilter = 'all' | LeadStatus;\n\nexport type OwnerFilter = 'all' | OwnerId;\n\nexport type LeadsState = {\n  query: string;\n  status: StatusFilter;\n  owner: OwnerFilter;\n  /** Null keeps the order of the list. */\n  sort: Sort | null;\n  page: number;\n  selected: string[];\n  litId: string | null;\n  filling: { id: string; field: Field } | null;\n  /** Cells that hold a value, as `id:field`. */\n  landed: string[];\n  settling: string | null;\n  spoken: string;\n};\n\nexport type LeadsAction =\n  | { type: 'queryTyped'; text: string }\n  | { type: 'statusPicked'; status: StatusFilter }\n  | { type: 'ownerPicked'; owner: OwnerFilter }\n  | { type: 'sorted'; column: SortColumn }\n  | { type: 'pageTurned'; page: number }\n  | { type: 'rowToggled'; id: string }\n  | { type: 'pageToggled' }\n  | { type: 'selectionCleared' }\n  | { type: 'filtersCleared' }\n  | { type: 'leadStarted'; id: string }\n  | { type: 'fetching'; id: string; field: Field }\n  | { type: 'landed'; id: string; field: Field }\n  | { type: 'leadFinished'; id: string };\n\ntype Step = SessionStep<LeadsState, LeadsAction>;\n\nexport const PAGE_SIZE = 8;\n\nexport const TOTAL = LEADS.length;\n\nexport const INITIAL: LeadsState = {\n  query: '',\n  status: 'all',\n  owner: 'all',\n  sort: null,\n  page: 0,\n  selected: [],\n  litId: null,\n  filling: null,\n  landed: [],\n  settling: null,\n  spoken: '',\n};\n\nexport function cellKeyOf(id: string, field: Field) {\n  return `${id}:${field}`;\n}\n\nexport function isLanded(state: LeadsState, id: string, field: Field) {\n  const key = cellKeyOf(id, field);\n  return state.landed.includes(key);\n}\n\nfunction isEnriched(state: LeadsState, lead: Lead) {\n  const hasEmail = isLanded(state, lead.id, 'email');\n  const hasSize = isLanded(state, lead.id, 'size');\n  return hasEmail && hasSize;\n}\n\nexport function enrichedCountOf(state: LeadsState) {\n  const enriched = LEADS.filter((lead) => isEnriched(state, lead));\n  return enriched.length;\n}\n\nfunction matchesQuery(lead: Lead, query: string) {\n  const wanted = query.trim().toLowerCase();\n  if (wanted === '') {\n    return true;\n  }\n  const text = `${lead.name} ${lead.company} ${lead.city}`;\n  const haystack = text.toLowerCase();\n  return haystack.includes(wanted);\n}\n\nfunction matchesStatus(lead: Lead, status: StatusFilter) {\n  if (status === 'all') {\n    return true;\n  }\n  return lead.status === status;\n}\n\nfunction matchesOwner(lead: Lead, owner: OwnerFilter) {\n  if (owner === 'all') {\n    return true;\n  }\n  return lead.owner === owner;\n}\n\nfunction sizeOf(state: LeadsState, lead: Lead) {\n  if (isLanded(state, lead.id, 'size')) {\n    return lead.employees;\n  }\n  return null;\n}\n\n/** A size the agent has not found yet sorts after every size, in both directions. */\nfunction compareSizes(\n  direction: SortDirection,\n  first: number | null,\n  second: number | null\n) {\n  if (first === null && second === null) {\n    return 0;\n  }\n  if (first === null) {\n    return 1;\n  }\n  if (second === null) {\n    return -1;\n  }\n  if (direction === 'asc') {\n    return first - second;\n  }\n  return second - first;\n}\n\nfunction textOrderOf(column: SortColumn, first: Lead, second: Lead) {\n  if (column === 'name') {\n    return first.name.localeCompare(second.name);\n  }\n  if (column === 'company') {\n    return first.company.localeCompare(second.company);\n  }\n  return STATUS_ORDER[first.status] - STATUS_ORDER[second.status];\n}\n\nfunction compareLeads(\n  state: LeadsState,\n  sort: Sort,\n  first: Lead,\n  second: Lead\n) {\n  if (sort.column === 'size') {\n    const firstSize = sizeOf(state, first);\n    const secondSize = sizeOf(state, second);\n    return compareSizes(sort.direction, firstSize, secondSize);\n  }\n  const order = textOrderOf(sort.column, first, second);\n  if (sort.direction === 'asc') {\n    return order;\n  }\n  return -order;\n}\n\nexport function resultOf(state: LeadsState) {\n  const kept = LEADS.filter((lead) => {\n    const fitsQuery = matchesQuery(lead, state.query);\n    const fitsStatus = matchesStatus(lead, state.status);\n    const fitsOwner = matchesOwner(lead, state.owner);\n    return fitsQuery && fitsStatus && fitsOwner;\n  });\n  const sort = state.sort;\n  if (sort === null) {\n    return kept;\n  }\n  return [...kept].sort((first, second) =>\n    compareLeads(state, sort, first, second)\n  );\n}\n\nexport function pageCountOf(total: number) {\n  const pages = Math.ceil(total / PAGE_SIZE);\n  return Math.max(1, pages);\n}\n\nexport function pageRowsOf(rows: Lead[], page: number) {\n  const start = page * PAGE_SIZE;\n  const end = start + PAGE_SIZE;\n  return rows.slice(start, end);\n}\n\nfunction withFilters(state: LeadsState, changes: Partial<LeadsState>) {\n  return { ...state, ...changes, page: 0 };\n}\n\nfunction sorted(state: LeadsState, column: SortColumn): LeadsState {\n  const current = state.sort;\n  if (current === null || current.column !== column) {\n    return { ...state, sort: { column, direction: 'asc' }, page: 0 };\n  }\n  if (current.direction === 'asc') {\n    return { ...state, sort: { column, direction: 'desc' }, page: 0 };\n  }\n  return { ...state, sort: null, page: 0 };\n}\n\nfunction rowToggled(state: LeadsState, id: string): LeadsState {\n  if (state.selected.includes(id)) {\n    const rest = state.selected.filter((selectedId) => selectedId !== id);\n    return { ...state, selected: rest };\n  }\n  return { ...state, selected: [...state.selected, id] };\n}\n\nfunction pageToggled(state: LeadsState): LeadsState {\n  const rows = pageRowsOf(resultOf(state), state.page);\n  const ids = rows.map((lead) => lead.id);\n  const isAllSelected = ids.every((id) => state.selected.includes(id));\n  if (isAllSelected) {\n    const rest = state.selected.filter((id) => !ids.includes(id));\n    return { ...state, selected: rest };\n  }\n  const added = ids.filter((id) => !state.selected.includes(id));\n  return { ...state, selected: [...state.selected, ...added] };\n}\n\nfunction landed(state: LeadsState, id: string, field: Field): LeadsState {\n  const key = cellKeyOf(id, field);\n  return {\n    ...state,\n    filling: null,\n    landed: [...state.landed, key],\n    settling: key,\n  };\n}\n\nfunction leadFinished(state: LeadsState, id: string): LeadsState {\n  const lead = leadOf(id);\n  const name = lead?.name ?? id;\n  const count = enrichedCountOf(state);\n  const spoken = `${AGENT.name} enriched ${name}: ${count} of ${TOTAL} leads`;\n  return { ...state, litId: null, spoken };\n}\n\nexport function reducer(state: LeadsState, action: LeadsAction): LeadsState {\n  switch (action.type) {\n    case 'queryTyped':\n      return withFilters(state, { query: action.text });\n    case 'statusPicked':\n      return withFilters(state, { status: action.status });\n    case 'ownerPicked':\n      return withFilters(state, { owner: action.owner });\n    case 'sorted':\n      return sorted(state, action.column);\n    case 'pageTurned':\n      return { ...state, page: action.page };\n    case 'rowToggled':\n      return rowToggled(state, action.id);\n    case 'pageToggled':\n      return pageToggled(state);\n    case 'selectionCleared':\n      return { ...state, selected: [] };\n    case 'filtersCleared':\n      return withFilters(state, { query: '', status: 'all', owner: 'all' });\n    case 'leadStarted':\n      return { ...state, litId: action.id, settling: null };\n    case 'fetching':\n      return { ...state, filling: { id: action.id, field: action.field } };\n    case 'landed':\n      return landed(state, action.id, action.field);\n    case 'leadFinished':\n      return leadFinished(state, action.id);\n  }\n}\n\nfunction leadSteps(id: string): Step[] {\n  return [\n    { after: 400, action: { type: 'leadStarted', id } },\n    { after: 250, action: { type: 'fetching', id, field: 'email' } },\n    { after: 850, action: { type: 'landed', id, field: 'email' } },\n    { after: 200, action: { type: 'fetching', id, field: 'size' } },\n    { after: 700, action: { type: 'landed', id, field: 'size' } },\n    { after: 350, action: { type: 'leadFinished', id } },\n  ];\n}\n\n/** The agent works on its own, so the pass goes on after a person takes over the table. */\nexport const SCRIPT: Step[] = PASS_IDS.flatMap((id) => leadSteps(id));\n\nfunction endOf(script: Step[]) {\n  let state = INITIAL;\n  for (const step of script) {\n    state = reducer(state, step.action);\n  }\n  return state;\n}\n\nexport const RESTING: LeadsState = { ...endOf(SCRIPT), settling: null };\n\nexport const LOOP_AFTER_MS = 4800;\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-03/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-03/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\n\nexport type LeadStatus = 'new' | 'contacted' | 'qualified';\n\nexport type OwnerId = 'grace' | 'samuel' | 'aline';\n\nexport type Owner = {\n  id: OwnerId;\n  name: string;\n  firstName: string;\n};\n\nexport const OWNERS: Owner[] = [\n  { id: 'grace', name: 'Grace Mbuyi', firstName: 'Grace' },\n  { id: 'samuel', name: 'Samuel Mukendi', firstName: 'Samuel' },\n  { id: 'aline', name: 'Aline Kasongo', firstName: 'Aline' },\n];\n\nexport type Lead = {\n  id: string;\n  name: string;\n  company: string;\n  city: string;\n  status: LeadStatus;\n  owner: OwnerId;\n  /** What the agent finds out. The table shows it once the agent has landed it. */\n  email: string;\n  employees: number;\n};\n\n/** Invented people at invented companies. The addresses use a reserved domain. */\nexport const LEADS: Lead[] = [\n  {\n    id: 'ilunga',\n    name: 'Patrick Ilunga',\n    company: 'Zomba Freight',\n    city: 'Lubumbashi',\n    status: 'qualified',\n    owner: 'grace',\n    email: 'p.ilunga@zomba-freight.example',\n    employees: 120,\n  },\n  {\n    id: 'mukendi',\n    name: 'Chantal Mukendi',\n    company: 'Lualaba Mills',\n    city: 'Kolwezi',\n    status: 'contacted',\n    owner: 'samuel',\n    email: 'c.mukendi@lualaba-mills.example',\n    employees: 340,\n  },\n  {\n    id: 'kabasele',\n    name: 'Joël Kabasele',\n    company: 'Ituri Tea Works',\n    city: 'Kisangani',\n    status: 'new',\n    owner: 'aline',\n    email: 'j.kabasele@ituri-tea.example',\n    employees: 58,\n  },\n  {\n    id: 'tshibangu',\n    name: 'Marie-Louise Tshibangu',\n    company: 'Nyiragongo Labs',\n    city: 'Goma',\n    status: 'qualified',\n    owner: 'grace',\n    email: 'ml.tshibangu@nyiragongo-labs.example',\n    employees: 24,\n  },\n  {\n    id: 'mbala',\n    name: 'Dieudonné Mbala',\n    company: 'Mbuji Cold Chain',\n    city: 'Mbuji-Mayi',\n    status: 'new',\n    owner: 'samuel',\n    email: 'd.mbala@mbuji-coldchain.example',\n    employees: 76,\n  },\n  {\n    id: 'kasongo',\n    name: 'Sylvie Kasongo',\n    company: 'Tshopo Logistics',\n    city: 'Kisangani',\n    status: 'contacted',\n    owner: 'aline',\n    email: 's.kasongo@tshopo-logistics.example',\n    employees: 210,\n  },\n  {\n    id: 'bahati',\n    name: 'Trésor Bahati',\n    company: 'Maniema Solar',\n    city: 'Bukavu',\n    status: 'new',\n    owner: 'grace',\n    email: 't.bahati@maniema-solar.example',\n    employees: 33,\n  },\n  {\n    id: 'mwamba',\n    name: 'Aline Mwamba',\n    company: 'Kasai Print House',\n    city: 'Kananga',\n    status: 'qualified',\n    owner: 'samuel',\n    email: 'a.mwamba@kasai-print.example',\n    employees: 18,\n  },\n  {\n    id: 'lukusa',\n    name: 'Fiston Lukusa',\n    company: 'Katanga Fresh',\n    city: 'Likasi',\n    status: 'contacted',\n    owner: 'aline',\n    email: 'f.lukusa@katanga-fresh.example',\n    employees: 95,\n  },\n  {\n    id: 'kalala',\n    name: 'Nadine Kalala',\n    company: 'Equateur Boats',\n    city: 'Mbandaka',\n    status: 'new',\n    owner: 'grace',\n    email: 'n.kalala@equateur-boats.example',\n    employees: 41,\n  },\n  {\n    id: 'mutombo',\n    name: 'Héritier Mutombo',\n    company: 'Boma Port Services',\n    city: 'Boma',\n    status: 'contacted',\n    owner: 'samuel',\n    email: 'h.mutombo@boma-port.example',\n    employees: 260,\n  },\n  {\n    id: 'nkulu',\n    name: 'Esther Nkulu',\n    company: 'Kisangani Bikes',\n    city: 'Kisangani',\n    status: 'qualified',\n    owner: 'aline',\n    email: 'e.nkulu@kisangani-bikes.example',\n    employees: 12,\n  },\n  {\n    id: 'mavungu',\n    name: 'Gloire Mavungu',\n    company: 'Likasi Copper Tools',\n    city: 'Likasi',\n    status: 'new',\n    owner: 'grace',\n    email: 'g.mavungu@likasi-copper.example',\n    employees: 88,\n  },\n  {\n    id: 'ngoy',\n    name: 'Rachel Ngoy',\n    company: 'Goma Coffee Roasters',\n    city: 'Goma',\n    status: 'qualified',\n    owner: 'samuel',\n    email: 'r.ngoy@goma-coffee.example',\n    employees: 29,\n  },\n  {\n    id: 'kitenge',\n    name: 'Bienvenu Kitenge',\n    company: 'Uvira Fisheries',\n    city: 'Uvira',\n    status: 'contacted',\n    owner: 'aline',\n    email: 'b.kitenge@uvira-fisheries.example',\n    employees: 64,\n  },\n  {\n    id: 'mulumba',\n    name: 'Clarisse Mulumba',\n    company: 'Kananga Radio',\n    city: 'Kananga',\n    status: 'new',\n    owner: 'grace',\n    email: 'c.mulumba@kananga-radio.example',\n    employees: 15,\n  },\n];\n\nexport const PASS_IDS = [\n  'ilunga',\n  'mukendi',\n  'kabasele',\n  'tshibangu',\n  'mbala',\n  'kasongo',\n];\n\nexport const AGENT: { name: string; series: SeriesSlot } = {\n  name: 'Researcher',\n  series: 3,\n};\n\nexport const STATUS_LABEL: Record<LeadStatus, string> = {\n  new: 'New',\n  contacted: 'Contacted',\n  qualified: 'Qualified',\n};\n\nexport const STATUS_ORDER: Record<LeadStatus, number> = {\n  new: 0,\n  contacted: 1,\n  qualified: 2,\n};\n\nconst FALLBACK_OWNER = OWNERS[0];\n\nexport function ownerOf(id: OwnerId) {\n  const owner = OWNERS.find((candidate) => candidate.id === id);\n  return owner ?? FALLBACK_OWNER;\n}\n\nexport function leadOf(id: string) {\n  return LEADS.find((candidate) => candidate.id === id);\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-03/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "ai-product"
  ],
  "type": "registry:block"
}