{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-data-01",
  "title": "Table you can ask",
  "description": "A customer table you ask in plain words: the question lands as chips you take off one by one while the count rolls, with saved views, sorting, pages, a bulk bar that picks an owner in place and a summary that unfolds under its row word by word.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.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/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/streamed-text.json",
    "https://ui.ndekocode.dev/r/table.json",
    "https://ui.ndekocode.dev/r/tabs.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/index.tsx",
      "content": "'use client';\n\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  pressedQuietOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { ChevronLeftIcon, ChevronRightIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport {\n  Pagination,\n  PaginationContent,\n  PaginationItem,\n} from '@/registry/ndeko/ui/pagination';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Tabs, TabsList, TabsPanel, TabsTab } from '@/registry/ndeko/ui/tabs';\n\nimport { AccountsTable } from './accounts-table';\nimport type { FilterKind } from './ask';\nimport { AskBar } from './ask-bar';\nimport { BulkBar } from './bulk-bar';\nimport { csvRowsOf, downloadCsv } from './csv';\nimport { TODAY_LABEL, type OwnerId } from './data';\nimport {\n  accountsWordOf,\n  INITIAL,\n  LOOP_AFTER_MS,\n  matchingOf,\n  PAGE_SIZE,\n  pageCountOf,\n  pageRowsOf,\n  reducer,\n  RESTING,\n  resultOf,\n  SCRIPT,\n  viewCountOf,\n  VIEWS,\n  type AccountsAction,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst FILE_NAME = 'accounts.csv';\n\nconst EXPORTED_FOR_MS = 1600;\n\n/** 1 to 8 of 24: the rows on screen out of the rows the filters keep. */\nfunction rangeLineOf(page: number, shown: number, total: number) {\n  if (total === 0) {\n    return 'No account';\n  }\n  const first = page * PAGE_SIZE + 1;\n  const last = first + shown - 1;\n  return `${first} to ${last} of ${total}`;\n}\n\nexport default function AiData01() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const { schedule } = useTimeouts();\n  const [isExported, setIsExported] = useState(false);\n  const { filters, view, sort, page } = state;\n  const matching = useMemo(() => matchingOf(filters), [filters]);\n  const result = useMemo(\n    () => resultOf(filters, view, sort),\n    [filters, view, sort]\n  );\n  const rows = useMemo(() => pageRowsOf(result, page), [result, page]);\n  const total = result.length;\n  const pageCount = pageCountOf(total);\n  const pageNumber = page + 1;\n  const isFirstPage = page === 0;\n  const isLastPage = pageNumber === pageCount;\n  const rangeLine = rangeLineOf(page, rows.length, total);\n  const hasChanged = state.revision > 0;\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 that removes the filters leaves with the empty state, so the focus goes back to the question box. */\n  const actOnTable = useCallback(\n    (action: AccountsAction) => {\n      act(action);\n      if (action.type === 'filtersCleared') {\n        focusLater('[data-ask-field]');\n      }\n    },\n    [act, focusLater]\n  );\n\n  /** A chip that is removed takes its button with it: the focus goes to the chip that takes its place, or to the question box. */\n  function removeFilter(kind: FilterKind) {\n    const kinds = filters.map((filter) => filter.kind);\n    const index = kinds.indexOf(kind);\n    const neighbour = kinds[index + 1] ?? kinds[index - 1];\n    act({ type: 'filterRemoved', kind });\n    if (neighbour) {\n      focusLater(`[data-filter-remove=\"${neighbour}\"]`);\n      return;\n    }\n    focusLater('[data-ask-field]');\n  }\n\n  function clearFilters() {\n    act({ type: 'filtersCleared' });\n    focusLater('[data-ask-field]');\n  }\n\n  function pickView(value: unknown) {\n    const picked = VIEWS.find((candidate) => candidate.id === value);\n    if (picked) {\n      act({ type: 'viewPicked', view: picked.id });\n    }\n  }\n\n  function showOwners() {\n    act({ type: 'bulkModeSet', mode: 'owners' });\n    focusLater('[data-bulk-owner]');\n  }\n\n  function hideOwners() {\n    act({ type: 'bulkModeSet', mode: 'actions' });\n    focusLater('[data-bulk-assign]');\n  }\n\n  /** The bar leaves once its accounts have their owner, so the focus goes back to the table. */\n  function assign(owner: OwnerId) {\n    act({ type: 'ownerAssigned', owner });\n    focusLater('[data-select-page]');\n  }\n\n  function clearSelection() {\n    act({ type: 'selectionCleared' });\n    focusLater('[data-select-page]');\n  }\n\n  function exportSelected() {\n    const chosen = result.filter((account) =>\n      state.selected.includes(account.id)\n    );\n    downloadCsv(FILE_NAME, csvRowsOf(chosen, state.owners));\n    act({ type: 'exported' });\n    setIsExported(true);\n    schedule(() => setIsExported(false), EXPORTED_FOR_MS);\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container min-h-dvh w-full'\n      >\n        <div className='mx-auto flex max-w-6xl flex-col gap-4 p-4 @3xl:gap-5 @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              <h1 className='text-lg font-semibold text-balance'>Accounts</h1>\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                  {accountsWordOf(total)}\n                </span>\n                <span aria-hidden='true'>·</span>\n                As of {TODAY_LABEL}\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          <AskBar\n            question={state.question}\n            hasAskFailed={state.hasAskFailed}\n            filters={filters}\n            pressed={pressed}\n            onType={(text) => act({ type: 'questionTyped', text })}\n            onAsk={() => act({ type: 'asked' })}\n            onRemove={removeFilter}\n            onClear={clearFilters}\n          />\n\n          <Tabs value={view} onValueChange={pickView} className='gap-4'>\n            <TabsList aria-label='Saved views'>\n              {VIEWS.map((candidate) => (\n                <TabsTab\n                  key={candidate.id}\n                  value={candidate.id}\n                  className={cn(\n                    'transition-[color,background-color,scale]',\n                    pressedQuietOf(pressed === `view-${candidate.id}`)\n                  )}\n                >\n                  {candidate.label}\n                  <span className='text-muted-foreground text-xs'>\n                    <MotionNumber value={viewCountOf(matching, candidate.id)} />\n                  </span>\n                </TabsTab>\n              ))}\n            </TabsList>\n            <TabsPanel value={view} className='flex flex-col gap-3'>\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                <AccountsTable\n                  rows={rows}\n                  owners={state.owners}\n                  sort={sort}\n                  selected={state.selected}\n                  openSummaries={state.openSummaries}\n                  writtenSummaries={state.writtenSummaries}\n                  streamingSummary={state.streamingSummary}\n                  hasChanged={hasChanged}\n                  pressed={pressed}\n                  onAction={actOnTable}\n                />\n              </div>\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: 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: page + 1 })\n                      }\n                    >\n                      <ChevronRightIcon />\n                    </Button>\n                  </PaginationItem>\n                </PaginationContent>\n              </Pagination>\n            </TabsPanel>\n          </Tabs>\n\n          <BulkBar\n            count={state.selected.length}\n            mode={state.bulkMode}\n            isExported={isExported}\n            pressed={pressed}\n            onShowOwners={showOwners}\n            onHideOwners={hideOwners}\n            onAssign={assign}\n            onExport={exportSelected}\n            onClear={clearSelection}\n          />\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/ask-bar.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type MotionProps } from 'motion/react';\nimport { useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  pressedQuietOf,\n  pressedSolidOf,\n} from '@/registry/ndeko/lib/demonstration';\nimport { XIcon } from '@/registry/ndeko/lib/icons';\nimport { EASE_OUT_STRONG, springOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { Input } from '@/registry/ndeko/ui/input';\n\nimport {\n  ASK_EXAMPLE,\n  ASK_FAILED_LINE,\n  filterLabelOf,\n  type Filter,\n  type FilterKind,\n} from './ask';\n\nconst CHIP =\n  'chip-3d inline-flex h-7 max-w-full items-center gap-0.5 rounded-md ps-2 pe-0.5 text-xs font-medium whitespace-nowrap [--chip:var(--primary)]';\n\nconst CHIP_REMOVE =\n  'focus-visible:ring-ring/25 hover:bg-foreground/[0.08] flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-sm opacity-70 transition-[opacity,background-color,scale] duration-150 outline-none hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-[3px]';\n\n/** The chips of one question land one after the other. */\nconst LANDING_STAGGER = 0.06;\n\nconst LEAVE = { duration: 0.12, ease: EASE_OUT_STRONG };\n\ntype ChipPresence = Pick<MotionProps, 'initial' | 'animate' | 'exit'>;\n\nconst CHIP_FADE: ChipPresence = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: LEAVE },\n};\n\n/** A chip settles from a slightly larger size. Reduced motion keeps the fade only. */\nfunction chipPresenceOf(\n  shouldReduceMotion: boolean,\n  order: number\n): ChipPresence {\n  if (shouldReduceMotion) {\n    return CHIP_FADE;\n  }\n  const delay = order * LANDING_STAGGER;\n  const land = { duration: 0.3, ease: EASE_OUT_STRONG, delay };\n  return {\n    initial: { opacity: 0, scale: 1.04 },\n    animate: { opacity: 1, scale: 1, transition: land },\n    exit: { opacity: 0, scale: 0.96, transition: LEAVE },\n  };\n}\n\nfunction describedByOf(hasAskFailed: boolean, hintId: string) {\n  if (hasAskFailed) {\n    return hintId;\n  }\n  return undefined;\n}\n\ntype AskBarProps = {\n  question: string;\n  hasAskFailed: boolean;\n  filters: Filter[];\n  pressed: string | null;\n  onType: (text: string) => void;\n  onAsk: () => void;\n  onRemove: (kind: FilterKind) => void;\n  onClear: () => void;\n};\n\nexport function AskBar({\n  question,\n  hasAskFailed,\n  filters,\n  pressed,\n  onType,\n  onAsk,\n  onRemove,\n  onClear,\n}: AskBarProps) {\n  const fieldId = useId();\n  const hintId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travel = springOf(shouldReduceMotion);\n  const kinds = filters.map((filter) => filter.kind);\n  const placement = kinds.join(' ');\n  const hasFilters = filters.length > 0;\n\n  function ask(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onAsk();\n  }\n\n  return (\n    <section aria-label='Ask the table' className='flex flex-col gap-2'>\n      <form onSubmit={ask} className='flex flex-col gap-1.5'>\n        <div className='flex items-center gap-2'>\n          <label\n            htmlFor={fieldId}\n            className='text-muted-foreground shrink-0 text-[13px]'\n          >\n            Show me\n          </label>\n          <Input\n            id={fieldId}\n            data-ask-field\n            autoComplete='off'\n            placeholder={ASK_EXAMPLE}\n            value={question}\n            aria-invalid={hasAskFailed}\n            aria-describedby={describedByOf(hasAskFailed, hintId)}\n            onChange={(event) => onType(event.target.value)}\n          />\n          <Button\n            type='submit'\n            className={cn('shrink-0', pressedSolidOf(pressed === 'ask'))}\n          >\n            Ask\n          </Button>\n        </div>\n        <Fold open={hasAskFailed}>\n          <p id={hintId} className='text-destructive-ink text-xs'>\n            {ASK_FAILED_LINE}\n          </p>\n        </Fold>\n      </form>\n      <div className='flex min-h-7 flex-wrap items-center gap-x-2 gap-y-1.5'>\n        {!hasFilters && (\n          <p className='text-muted-foreground text-xs'>\n            Name a plan, a region, seats over or under a number, or what renews\n            this quarter\n          </p>\n        )}\n        <ul\n          aria-label='Filters'\n          className='relative flex flex-wrap items-center gap-1.5'\n        >\n          <AnimatePresence mode='popLayout' initial={false}>\n            {filters.map((filter, index) => {\n              const label = filterLabelOf(filter);\n              const isPressed = pressed === `chip-${filter.kind}`;\n              return (\n                <motion.li\n                  key={filter.kind}\n                  layout='position'\n                  layoutDependency={placement}\n                  {...chipPresenceOf(shouldReduceMotion, index)}\n                  transition={{ layout: travel }}\n                  className='max-w-full'\n                >\n                  <span className={CHIP}>\n                    <span className='min-w-0 truncate'>{label}</span>\n                    <button\n                      type='button'\n                      data-filter-remove={filter.kind}\n                      aria-label={`Remove the filter ${label}`}\n                      onClick={() => onRemove(filter.kind)}\n                      className={cn(CHIP_REMOVE, pressedQuietOf(isPressed))}\n                    >\n                      <XIcon className='size-3.5' />\n                    </button>\n                  </span>\n                </motion.li>\n              );\n            })}\n          </AnimatePresence>\n        </ul>\n        {hasFilters && (\n          <Button\n            type='button'\n            variant='ghost'\n            size='sm'\n            onClick={onClear}\n            className='text-muted-foreground'\n          >\n            Clear filters\n          </Button>\n        )}\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/ask-bar.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/accounts-table.tsx",
      "content": "'use client';\n\nimport { memo, useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon, TextQuoteIcon } 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 { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Checkbox } from '@/registry/ndeko/ui/checkbox';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { StreamedInk } from '@/registry/ndeko/ui/streamed-text';\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHead,\n  TableHeader,\n  TableRow,\n} from '@/registry/ndeko/ui/table';\n\nimport {\n  HEALTH_LABEL,\n  ownerOf,\n  PLAN_LABEL,\n  REGION_LABEL,\n  renewalLabelOf,\n  summaryOf,\n  type Account,\n  type Health,\n  type OwnerId,\n} from './data';\nimport {\n  ownerIdOf,\n  SORT_LABEL,\n  type AccountsAction,\n  type Owners,\n  type Sort,\n  type SortColumn,\n  type SortDirection,\n} from './session';\n\nconst COLUMN_COUNT = 9;\n\n/** How long one word of a summary takes to follow the one before it. */\nconst WORD_MS = 45;\n\nconst HEALTH_VARIANT: Record<Health, 'success' | 'warning' | 'destructive'> = {\n  healthy: 'success',\n  watch: 'warning',\n  risk: 'destructive',\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\n/**\n * The table scrolls sideways inside its frame on a narrow page. What belongs to a whole row (its\n * summary, the empty state) stays as wide as the frame and holds to its left edge, so it is read\n * without scrolling.\n */\nconst FRAME_WIDE = 'sticky left-0 w-[100cqw]';\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;\n  pressed: string | null;\n  /** A column of figures: the label ends where the figures end, the arrow sits before it. */\n  isFigure?: boolean;\n  onAction: (action: AccountsAction) => void;\n};\n\nfunction SortHead({\n  column,\n  sort,\n  pressed,\n  isFigure = false,\n  onAction,\n}: SortHeadProps) {\n  const isSorted = sort.column === column;\n  const isPressed = pressed === `sort-${column}`;\n\n  return (\n    <TableHead\n      aria-sort={ariaSortOf(isSorted, sort.direction)}\n      className={cn(isFigure && 'text-end')}\n    >\n      <button\n        type='button'\n        onClick={() => onAction({ type: 'sorted', column })}\n        className={cn(\n          SORT_BUTTON,\n          isFigure && 'flex-row-reverse',\n          pressedQuietOf(isPressed)\n        )}\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, sort.direction)\n          )}\n        />\n      </button>\n    </TableHead>\n  );\n}\n\nfunction selectedStateOf(isSelected: boolean) {\n  if (isSelected) {\n    return 'selected';\n  }\n  return undefined;\n}\n\n/** A row that arrives after the first change of the list fades in. Nothing fades when the page loads. */\nfunction arrivalOf(hasChanged: boolean) {\n  if (hasChanged) {\n    return 'transition-[background-color,opacity] duration-[150ms,300ms] starting:opacity-0';\n  }\n  return undefined;\n}\n\n/** A gradient alone names nobody: the first name sits beside it, the full name once the table has room. */\nfunction OwnerCell({ ownerId }: { ownerId: OwnerId }) {\n  const owner = ownerOf(ownerId);\n\n  return (\n    <Swap swapKey={owner.id}>\n      <span className='flex items-center gap-2 whitespace-nowrap'>\n        <Avatar seed={owner.name} className='size-5' />\n        <span className='@5xl:hidden'>{owner.firstName}</span>\n        <span className='hidden @5xl:inline'>{owner.name}</span>\n      </span>\n    </Swap>\n  );\n}\n\ntype AccountRowProps = {\n  account: Account;\n  ownerId: OwnerId;\n  isSelected: boolean;\n  isSummaryOpen: boolean;\n  isSummaryWritten: boolean;\n  isSummaryStreaming: boolean;\n  isLast: boolean;\n  hasChanged: boolean;\n  pressed: string | null;\n  onAction: (action: AccountsAction) => void;\n};\n\nfunction AccountRow({\n  account,\n  ownerId,\n  isSelected,\n  isSummaryOpen,\n  isSummaryWritten,\n  isSummaryStreaming,\n  isLast,\n  hasChanged,\n  pressed,\n  onAction,\n}: AccountRowProps) {\n  const summaryId = useId();\n  const isSelectPressed = pressed === `select-${account.id}`;\n  const isSummarizePressed = pressed === `summarize-${account.id}`;\n  const endsTheList = isLast && !isSummaryOpen;\n  const hasLineUnderSummary = isSummaryOpen && !isLast;\n\n  return (\n    <>\n      <TableRow\n        data-state={selectedStateOf(isSelected)}\n        className={cn('h-12', arrivalOf(hasChanged), endsTheList && 'border-0')}\n      >\n        <TableCell className='py-0'>\n          <Checkbox\n            checked={isSelected}\n            aria-label={`Select ${account.name}`}\n            onCheckedChange={() =>\n              onAction({ type: 'rowToggled', id: account.id })\n            }\n            className={cn(\n              'transition-[background-color,box-shadow,scale]',\n              pressedQuietOf(isSelectPressed)\n            )}\n          />\n        </TableCell>\n        <TableCell className='w-full max-w-0 py-0'>\n          <span className='flex min-w-0 items-center gap-2.5'>\n            <CompanyMark seed={account.name} />\n            <span className='truncate font-medium'>{account.name}</span>\n          </span>\n        </TableCell>\n        <TableCell className='py-0 whitespace-nowrap'>\n          {PLAN_LABEL[account.plan]}\n        </TableCell>\n        <TableCell className='text-muted-foreground hidden py-0 whitespace-nowrap @4xl:table-cell'>\n          {REGION_LABEL[account.region]}\n        </TableCell>\n        <TableCell className='py-0 text-end tabular-nums'>\n          {account.seats}\n        </TableCell>\n        <TableCell className='py-0 whitespace-nowrap tabular-nums'>\n          {renewalLabelOf(account.renewal)}\n        </TableCell>\n        <TableCell className='py-0'>\n          <Badge variant={HEALTH_VARIANT[account.health]}>\n            {HEALTH_LABEL[account.health]}\n          </Badge>\n        </TableCell>\n        <TableCell className='py-0'>\n          <OwnerCell ownerId={ownerId} />\n        </TableCell>\n        <TableCell className='py-0 ps-0'>\n          <Button\n            type='button'\n            variant='ghost'\n            size='sm'\n            aria-label={`Summarize ${account.name}`}\n            aria-expanded={isSummaryOpen}\n            aria-controls={summaryId}\n            onClick={() => onAction({ type: 'summaryToggled', id: account.id })}\n            className={cn(\n              'text-muted-foreground',\n              pressedQuietOf(isSummarizePressed)\n            )}\n          >\n            <TextQuoteIcon />\n            <span className='hidden @3xl:inline'>Summarize</span>\n          </Button>\n        </TableCell>\n      </TableRow>\n      <tr className={cn(hasLineUnderSummary && 'hairline-b border-border')}>\n        <td colSpan={COLUMN_COUNT} className='p-0'>\n          <div className={cn(FRAME_WIDE, 'px-1')}>\n            <Fold open={isSummaryOpen} id={summaryId}>\n              {isSummaryWritten && (\n                <div className='bg-foreground/[0.03] my-1 flex flex-col gap-1.5 rounded-md px-3 py-2.5 @3xl:ps-[3.25rem]'>\n                  <p className='max-w-prose text-[13px] leading-relaxed'>\n                    <StreamedInk\n                      text={summaryOf(account)}\n                      isStreaming={isSummaryStreaming}\n                      wordMs={WORD_MS}\n                    />\n                  </p>\n                  <p className='text-muted-foreground text-xs'>\n                    Written from this row\n                  </p>\n                </div>\n              )}\n            </Fold>\n          </div>\n        </td>\n      </tr>\n    </>\n  );\n}\n\ntype SelectPageBoxProps = {\n  rowIds: string[];\n  selected: string[];\n  onAction: (action: AccountsAction) => 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 accounts of this page'\n      onCheckedChange={() => onAction({ type: 'pageToggled' })}\n    />\n  );\n}\n\n/** Under reduced motion a summary is there at once. */\nfunction streamingIdOf(\n  streamingSummary: string | null,\n  shouldReduceMotion: boolean\n) {\n  if (shouldReduceMotion) {\n    return null;\n  }\n  return streamingSummary;\n}\n\nexport type AccountsTableProps = {\n  rows: Account[];\n  owners: Owners;\n  sort: Sort;\n  selected: string[];\n  openSummaries: string[];\n  writtenSummaries: string[];\n  streamingSummary: string | null;\n  hasChanged: boolean;\n  pressed: string | null;\n  onAction: (action: AccountsAction) => void;\n};\n\n/** Memoised: a key typed in the question box above does not draw the rows again. */\nexport const AccountsTable = memo(function AccountsTable({\n  rows,\n  owners,\n  sort,\n  selected,\n  openSummaries,\n  writtenSummaries,\n  streamingSummary,\n  hasChanged,\n  pressed,\n  onAction,\n}: AccountsTableProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const streamingId = streamingIdOf(streamingSummary, shouldReduceMotion);\n  const rowIds = rows.map((account) => account.id);\n  const lastIndex = rows.length - 1;\n  const isEmpty = rows.length === 0;\n  const sortHead = { sort, pressed, onAction };\n\n  return (\n    <Table className='min-w-[44rem]'>\n      <caption className='sr-only'>Customer accounts</caption>\n      <TableHeader>\n        <TableRow className='hover:bg-transparent'>\n          <TableHead>\n            <SelectPageBox\n              rowIds={rowIds}\n              selected={selected}\n              onAction={onAction}\n            />\n          </TableHead>\n          <SortHead column='name' {...sortHead} />\n          <SortHead column='plan' {...sortHead} />\n          <TableHead className='hidden @4xl:table-cell'>Region</TableHead>\n          <SortHead column='seats' isFigure {...sortHead} />\n          <SortHead column='renewal' {...sortHead} />\n          <TableHead>Health</TableHead>\n          <TableHead>Owner</TableHead>\n          <TableHead className='ps-0'>\n            <span className='sr-only'>Summary</span>\n          </TableHead>\n        </TableRow>\n      </TableHeader>\n      <TableBody>\n        {rows.map((account, index) => (\n          <AccountRow\n            key={account.id}\n            account={account}\n            ownerId={ownerIdOf(owners, account)}\n            isSelected={selected.includes(account.id)}\n            isSummaryOpen={openSummaries.includes(account.id)}\n            isSummaryWritten={writtenSummaries.includes(account.id)}\n            isSummaryStreaming={streamingId === account.id}\n            isLast={index === lastIndex}\n            hasChanged={hasChanged}\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 account 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-data-01/accounts-table.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/bulk-bar.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { XIcon } from '@/registry/ndeko/lib/icons';\nimport { risePresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\n\nimport { OWNERS, type OwnerId } from './data';\nimport type { BulkMode } from './session';\n\n/** What the bar offers arrives with a fade, since the bar changes width around it. */\nconst CHOICES =\n  'flex items-center gap-1 transition-opacity duration-200 starting:opacity-0';\n\nfunction exportWordOf(isExported: boolean) {\n  if (isExported) {\n    return 'Exported';\n  }\n  return 'Export';\n}\n\n/** On a narrow bar the names of the owners need the room the count takes while one is picked. */\nfunction countVisibilityOf(isPickingOwner: boolean) {\n  if (isPickingOwner) {\n    return 'hidden @lg:flex';\n  }\n  return 'flex';\n}\n\ntype BulkBarProps = {\n  count: number;\n  mode: BulkMode;\n  isExported: boolean;\n  pressed: string | null;\n  onShowOwners: () => void;\n  onHideOwners: () => void;\n  onAssign: (owner: OwnerId) => void;\n  onExport: () => void;\n  onClear: () => void;\n};\n\n/**\n * The bar keeps its place at the foot of the block whether it shows or not, so selecting a row\n * moves nothing. The owners are picked in the bar itself: no layer opens over the table.\n */\nexport function BulkBar({\n  count,\n  mode,\n  isExported,\n  pressed,\n  onShowOwners,\n  onHideOwners,\n  onAssign,\n  onExport,\n  onClear,\n}: BulkBarProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const presence = risePresenceOf(shouldReduceMotion);\n  const hasSelection = count > 0;\n  const isPickingOwner = mode === 'owners';\n  const exportWord = exportWordOf(isExported);\n\n  function leaveOwnersOnEscape(event: React.KeyboardEvent<HTMLElement>) {\n    const isEscape = event.key === 'Escape';\n    if (isEscape && isPickingOwner) {\n      onHideOwners();\n    }\n  }\n\n  return (\n    <div className='pointer-events-none sticky bottom-4 z-10 flex h-11 justify-center'>\n      <AnimatePresence initial={false}>\n        {hasSelection && (\n          <motion.section\n            key='bulk'\n            aria-label='Selected accounts'\n            onKeyDown={leaveOwnersOnEscape}\n            className='surface-raised pointer-events-auto flex h-11 max-w-full items-center gap-2 rounded-full ps-4 pe-1.5'\n            {...presence}\n          >\n            <p\n              className={cn(\n                'shrink-0 items-baseline gap-1 text-[13px] font-medium',\n                countVisibilityOf(isPickingOwner)\n              )}\n            >\n              <MotionNumber value={count} />\n              selected\n            </p>\n            <AnimatedSize axis='width'>\n              {isPickingOwner && (\n                <div role='group' aria-label='Assign to' className={CHOICES}>\n                  <span className='text-muted-foreground hidden pe-1 text-xs @lg:inline'>\n                    Assign to\n                  </span>\n                  {OWNERS.map((owner) => (\n                    <Button\n                      key={owner.id}\n                      type='button'\n                      variant='ghost'\n                      size='sm'\n                      data-bulk-owner={owner.id}\n                      aria-label={`Assign to ${owner.name}`}\n                      onClick={() => onAssign(owner.id)}\n                      className={cn(\n                        'gap-1 px-1.5 @lg:gap-1.5',\n                        pressedQuietOf(pressed === `owner-${owner.id}`)\n                      )}\n                    >\n                      <Avatar seed={owner.name} className='size-4 @lg:size-5' />\n                      {owner.firstName}\n                    </Button>\n                  ))}\n                  <Button\n                    type='button'\n                    variant='ghost'\n                    size='icon-sm'\n                    aria-label='Back to the actions'\n                    onClick={onHideOwners}\n                    className='text-muted-foreground'\n                  >\n                    <XIcon />\n                  </Button>\n                </div>\n              )}\n              {!isPickingOwner && (\n                <div className={CHOICES}>\n                  <Button\n                    type='button'\n                    variant='ghost'\n                    size='sm'\n                    data-bulk-assign\n                    onClick={onShowOwners}\n                    className={pressedQuietOf(pressed === 'assign')}\n                  >\n                    Assign owner\n                  </Button>\n                  <Button\n                    type='button'\n                    variant='ghost'\n                    size='sm'\n                    onClick={onExport}\n                  >\n                    <Swap swapKey={exportWord}>{exportWord}</Swap>\n                  </Button>\n                  <Button\n                    type='button'\n                    variant='ghost'\n                    size='icon-sm'\n                    aria-label='Clear the selection'\n                    onClick={onClear}\n                    className='text-muted-foreground'\n                  >\n                    <XIcon />\n                  </Button>\n                </div>\n              )}\n            </AnimatedSize>\n          </motion.section>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/bulk-bar.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/ask.ts",
      "content": "import {\n  PLAN_LABEL,\n  PLANS,\n  REGION_LABEL,\n  REGIONS,\n  renewsThisQuarter,\n  type Account,\n  type PlanId,\n  type RegionId,\n} from './data';\n\nexport const ASK_EXAMPLE = 'enterprise in europe over 100 seats';\n\nexport const ASK_FAILED_LINE =\n  'Nothing to filter in that. Name a plan, a region, seats over or under a number, or what renews this quarter.';\n\nexport type Filter =\n  | { kind: 'plan'; plans: PlanId[] }\n  | { kind: 'region'; regions: RegionId[] }\n  | { kind: 'seatsOver'; count: number }\n  | { kind: 'seatsUnder'; count: number }\n  | { kind: 'renewal' };\n\nexport type FilterKind = Filter['kind'];\n\nconst PLAN_PHRASES: Record<PlanId, string[]> = {\n  starter: ['starter'],\n  team: ['team', 'teams'],\n  business: ['business'],\n  enterprise: ['enterprise', 'enterprises'],\n};\n\nconst REGION_PHRASES: Record<RegionId, string[]> = {\n  europe: ['europe', 'european', 'eu'],\n  'north-america': ['north america', 'north american', 'usa', 'canada'],\n  'asia-pacific': ['asia pacific', 'asia', 'asian', 'apac'],\n  'latin-america': ['latin america', 'latin american', 'latam'],\n};\n\nconst RENEWAL_PHRASES = [\n  'renew',\n  'renews',\n  'renewing',\n  'renewal',\n  'renewals',\n  'expires',\n  'expiring',\n];\n\nconst OVER = /\\b(?:over|above|more than|bigger than|larger than) (\\d+)\\b/;\n\nconst UNDER = /\\b(?:under|below|fewer than|less than|smaller than) (\\d+)\\b/;\n\n/** Lower case words between single spaces, with a space at both ends so a phrase is matched whole. */\nfunction sentenceOf(text: string) {\n  const lowered = text.toLowerCase();\n  const spaced = lowered.replace(/[^a-z0-9]+/g, ' ');\n  const trimmed = spaced.trim();\n  return ` ${trimmed} `;\n}\n\nfunction names(sentence: string, phrases: string[]) {\n  return phrases.some((phrase) => sentence.includes(` ${phrase} `));\n}\n\nfunction countAfter(sentence: string, bound: RegExp) {\n  const match = bound.exec(sentence);\n  if (!match) {\n    return null;\n  }\n  return Number(match[1]);\n}\n\n/**\n * Reads a plain question into filters with a handful of word lists: no model is called.\n * It returns nothing when the question names nothing the table can filter on.\n */\nexport function filtersOfQuestion(text: string): Filter[] | null {\n  const sentence = sentenceOf(text);\n  const filters: Filter[] = [];\n  const plans = PLANS.filter((plan) => names(sentence, PLAN_PHRASES[plan]));\n  if (plans.length > 0) {\n    filters.push({ kind: 'plan', plans });\n  }\n  const regions = REGIONS.filter((region) =>\n    names(sentence, REGION_PHRASES[region])\n  );\n  if (regions.length > 0) {\n    filters.push({ kind: 'region', regions });\n  }\n  const over = countAfter(sentence, OVER);\n  if (over !== null) {\n    filters.push({ kind: 'seatsOver', count: over });\n  }\n  const under = countAfter(sentence, UNDER);\n  if (under !== null) {\n    filters.push({ kind: 'seatsUnder', count: under });\n  }\n  if (names(sentence, RENEWAL_PHRASES)) {\n    filters.push({ kind: 'renewal' });\n  }\n  if (filters.length === 0) {\n    return null;\n  }\n  return filters;\n}\n\n/** A new question adds to what is already asked: it replaces a filter of the same kind and keeps the others in place. */\nexport function mergedFilters(current: Filter[], asked: Filter[]) {\n  const kept = current.map((filter) => {\n    const replacement = asked.find(\n      (candidate) => candidate.kind === filter.kind\n    );\n    return replacement ?? filter;\n  });\n  const currentKinds = current.map((filter) => filter.kind);\n  const added = asked.filter((filter) => !currentKinds.includes(filter.kind));\n  return [...kept, ...added];\n}\n\nfunction orListOf(labels: string[]) {\n  return labels.join(' or ');\n}\n\nexport function filterLabelOf(filter: Filter) {\n  switch (filter.kind) {\n    case 'plan': {\n      const labels = filter.plans.map((plan) => PLAN_LABEL[plan]);\n      return `Plan: ${orListOf(labels)}`;\n    }\n    case 'region': {\n      const labels = filter.regions.map((region) => REGION_LABEL[region]);\n      return `Region: ${orListOf(labels)}`;\n    }\n    case 'seatsOver':\n      return `Seats over ${filter.count}`;\n    case 'seatsUnder':\n      return `Seats under ${filter.count}`;\n    case 'renewal':\n      return 'Renews this quarter';\n  }\n}\n\nexport function matchesFilter(account: Account, filter: Filter) {\n  switch (filter.kind) {\n    case 'plan':\n      return filter.plans.includes(account.plan);\n    case 'region':\n      return filter.regions.includes(account.region);\n    case 'seatsOver':\n      return account.seats > filter.count;\n    case 'seatsUnder':\n      return account.seats < filter.count;\n    case 'renewal':\n      return renewsThisQuarter(account);\n  }\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/ask.ts"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/csv.ts",
      "content": "import {\n  HEALTH_LABEL,\n  ownerOf,\n  PLAN_LABEL,\n  REGION_LABEL,\n  type Account,\n} from './data';\nimport { ownerIdOf, type Owners } from './session';\n\nconst HEADER = [\n  'Account',\n  'Plan',\n  'Region',\n  'Seats',\n  'Renewal',\n  'Health',\n  'Owner',\n];\n\nconst FORMULA_PREFIXES = ['=', '+', '-', '@'];\n\n/** Spreadsheet apps run a cell that starts with these characters as a formula. */\nfunction neutralizedCellOf(value: string) {\n  const startsLikeFormula = FORMULA_PREFIXES.some((prefix) =>\n    value.startsWith(prefix)\n  );\n  if (startsLikeFormula) {\n    return `'${value}`;\n  }\n  return value;\n}\n\nfunction csvCellOf(value: string) {\n  const neutralized = neutralizedCellOf(value);\n  const escaped = neutralized.replaceAll('\"', '\"\"');\n  return `\"${escaped}\"`;\n}\n\nfunction csvLineOf(row: string[]) {\n  const cells = row.map(csvCellOf);\n  return cells.join(',');\n}\n\n/** One line per account, with the owner a person may have assigned since the page loaded. */\nexport function csvRowsOf(accounts: Account[], owners: Owners) {\n  const rows = accounts.map((account) => {\n    const ownerId = ownerIdOf(owners, account);\n    return [\n      account.name,\n      PLAN_LABEL[account.plan],\n      REGION_LABEL[account.region],\n      String(account.seats),\n      account.renewal,\n      HEALTH_LABEL[account.health],\n      ownerOf(ownerId).name,\n    ];\n  });\n  return [HEADER, ...rows];\n}\n\n/** Builds the file in the browser and hands it to the download bar: nothing leaves the page. */\nexport function downloadCsv(fileName: string, rows: string[][]) {\n  const lines = rows.map(csvLineOf);\n  const text = lines.join('\\n');\n  const file = new Blob([text], { type: 'text/csv;charset=utf-8' });\n  const url = URL.createObjectURL(file);\n  const link = document.createElement('a');\n  link.href = url;\n  link.download = fileName;\n  link.click();\n  window.setTimeout(() => URL.revokeObjectURL(url), 0);\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/csv.ts"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\n\nimport {\n  ASK_EXAMPLE,\n  ASK_FAILED_LINE,\n  filtersOfQuestion,\n  matchesFilter,\n  mergedFilters,\n  type Filter,\n  type FilterKind,\n} from './ask';\nimport {\n  accountOf,\n  ACCOUNTS,\n  ownerOf,\n  PLAN_RANK,\n  renewsThisQuarter,\n  summaryOf,\n  type Account,\n  type OwnerId,\n} from './data';\n\nexport type ViewId = 'all' | 'risk' | 'renewing';\n\nexport type View = {\n  id: ViewId;\n  label: string;\n};\n\nexport const VIEWS: View[] = [\n  { id: 'all', label: 'All' },\n  { id: 'risk', label: 'At risk' },\n  { id: 'renewing', label: 'Renewing' },\n];\n\nexport type SortColumn = 'name' | 'plan' | 'seats' | 'renewal';\n\nexport type SortDirection = 'asc' | 'desc';\n\nexport type Sort = {\n  column: SortColumn;\n  direction: SortDirection;\n};\n\nexport const SORT_LABEL: Record<SortColumn, string> = {\n  name: 'Account',\n  plan: 'Plan',\n  seats: 'Seats',\n  renewal: 'Renewal',\n};\n\n/** A column of figures starts from the largest; names and dates start from the first. */\nconst FIRST_DIRECTION: Record<SortColumn, SortDirection> = {\n  name: 'asc',\n  plan: 'desc',\n  seats: 'desc',\n  renewal: 'asc',\n};\n\nconst DIRECTION_WORD: Record<SortDirection, string> = {\n  asc: 'ascending',\n  desc: 'descending',\n};\n\nexport type BulkMode = 'actions' | 'owners';\n\nexport type Owners = Partial<Record<string, OwnerId>>;\n\nexport const PAGE_SIZE = 8;\n\nexport type AccountsState = {\n  question: string;\n  hasAskFailed: boolean;\n  filters: Filter[];\n  view: ViewId;\n  sort: Sort;\n  page: number;\n  selected: string[];\n  bulkMode: BulkMode;\n  /** The owners a person assigned, by account. The others keep the owner of the data. */\n  owners: Owners;\n  openSummaries: string[];\n  /** A summary is written once: opened again, it is there at once. */\n  writtenSummaries: string[];\n  /** The summary whose words are arriving. */\n  streamingSummary: string | null;\n  /** Counts the changes of the rows on screen. Rows only fade in after the first one, never on load. */\n  revision: number;\n  spoken: string;\n};\n\nexport type AccountsAction =\n  | { type: 'questionTyped'; text: string }\n  | { type: 'asked' }\n  | { type: 'filterRemoved'; kind: FilterKind }\n  | { type: 'filtersCleared' }\n  | { type: 'viewPicked'; view: ViewId }\n  | { type: 'sorted'; column: SortColumn }\n  | { type: 'pageTurned'; page: number }\n  | { type: 'rowToggled'; id: string }\n  | { type: 'pageToggled' }\n  | { type: 'selectionCleared' }\n  | { type: 'bulkModeSet'; mode: BulkMode }\n  | { type: 'ownerAssigned'; owner: OwnerId }\n  | { type: 'exported' }\n  | { type: 'summaryToggled'; id: string };\n\ntype Step = SessionStep<AccountsState, AccountsAction>;\n\nexport const INITIAL: AccountsState = {\n  question: '',\n  hasAskFailed: false,\n  filters: [],\n  view: 'all',\n  sort: { column: 'name', direction: 'asc' },\n  page: 0,\n  selected: [],\n  bulkMode: 'actions',\n  owners: {},\n  openSummaries: [],\n  writtenSummaries: [],\n  streamingSummary: null,\n  revision: 0,\n  spoken: '',\n};\n\nexport function ownerIdOf(owners: Owners, account: Account) {\n  return owners[account.id] ?? account.owner;\n}\n\nfunction isInView(account: Account, view: ViewId) {\n  if (view === 'risk') {\n    return account.health === 'risk';\n  }\n  if (view === 'renewing') {\n    return renewsThisQuarter(account);\n  }\n  return true;\n}\n\n/** The accounts the filters keep, whatever the view. The tabs count from them. */\nexport function matchingOf(filters: Filter[]) {\n  return ACCOUNTS.filter((account) =>\n    filters.every((filter) => matchesFilter(account, filter))\n  );\n}\n\nexport function viewCountOf(matching: Account[], view: ViewId) {\n  const inView = matching.filter((account) => isInView(account, view));\n  return inView.length;\n}\n\nfunction orderOf(first: Account, second: Account, column: SortColumn) {\n  if (column === 'seats') {\n    return first.seats - second.seats;\n  }\n  if (column === 'plan') {\n    return PLAN_RANK[first.plan] - PLAN_RANK[second.plan];\n  }\n  if (column === 'renewal') {\n    return first.renewal.localeCompare(second.renewal);\n  }\n  return first.name.localeCompare(second.name);\n}\n\n/** Two accounts level on the sorted column keep the order of their names, whatever the direction. */\nfunction sortedBy(accounts: Account[], sort: Sort) {\n  const sorted = [...accounts];\n  sorted.sort((first, second) => {\n    const order = orderOf(first, second, sort.column);\n    if (order === 0) {\n      return first.name.localeCompare(second.name);\n    }\n    if (sort.direction === 'desc') {\n      return -order;\n    }\n    return order;\n  });\n  return sorted;\n}\n\nexport function resultOf(filters: Filter[], view: ViewId, sort: Sort) {\n  const matching = matchingOf(filters);\n  const inView = matching.filter((account) => isInView(account, view));\n  return sortedBy(inView, sort);\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(result: Account[], page: number) {\n  const start = page * PAGE_SIZE;\n  return result.slice(start, start + PAGE_SIZE);\n}\n\nexport function accountsWordOf(count: number) {\n  if (count === 1) {\n    return 'account';\n  }\n  return 'accounts';\n}\n\nfunction countLineOf(count: number) {\n  return `${count} ${accountsWordOf(count)}`;\n}\n\nfunction resultOfState(state: AccountsState) {\n  return resultOf(state.filters, state.view, state.sort);\n}\n\n/** The bar shows its actions again once nothing is selected. */\nfunction bulkModeFor(selected: string[], mode: BulkMode): BulkMode {\n  if (selected.length === 0) {\n    return 'actions';\n  }\n  return mode;\n}\n\n/**\n * The rows changed: the list starts again at its first page, and a selected account that left the\n * list leaves the selection, so a bulk action never touches a row nobody can see.\n */\nfunction withNewResult(\n  state: AccountsState,\n  spokenOf: (count: number) => string\n): AccountsState {\n  const result = resultOfState(state);\n  const visibleIds = result.map((account) => account.id);\n  const selected = state.selected.filter((id) => visibleIds.includes(id));\n  return {\n    ...state,\n    page: 0,\n    selected,\n    bulkMode: bulkModeFor(selected, state.bulkMode),\n    streamingSummary: null,\n    revision: state.revision + 1,\n    spoken: spokenOf(result.length),\n  };\n}\n\nfunction matchLineOf(count: number) {\n  if (count === 1) {\n    return '1 account matches';\n  }\n  return `${count} accounts match`;\n}\n\nfunction asked(state: AccountsState): AccountsState {\n  const askedFilters = filtersOfQuestion(state.question);\n  if (!askedFilters) {\n    return { ...state, hasAskFailed: true, spoken: ASK_FAILED_LINE };\n  }\n  const filters = mergedFilters(state.filters, askedFilters);\n  const next = { ...state, filters, question: '', hasAskFailed: false };\n  return withNewResult(next, matchLineOf);\n}\n\nfunction filterRemoved(state: AccountsState, kind: FilterKind): AccountsState {\n  const filters = state.filters.filter((filter) => filter.kind !== kind);\n  const next = { ...state, filters };\n  return withNewResult(\n    next,\n    (count) => `Filter removed, ${countLineOf(count)}`\n  );\n}\n\nfunction filtersCleared(state: AccountsState): AccountsState {\n  const next = { ...state, filters: [], hasAskFailed: false };\n  return withNewResult(next, (count) => `No filter, ${countLineOf(count)}`);\n}\n\nfunction viewLabelOf(id: ViewId) {\n  const view = VIEWS.find((candidate) => candidate.id === id);\n  return view?.label ?? '';\n}\n\nfunction viewPicked(state: AccountsState, view: ViewId): AccountsState {\n  if (state.view === view) {\n    return state;\n  }\n  const label = viewLabelOf(view);\n  const next = { ...state, view };\n  return withNewResult(next, (count) => `${label}, ${countLineOf(count)}`);\n}\n\nfunction directionAfter(sort: Sort, column: SortColumn): SortDirection {\n  if (sort.column !== column) {\n    return FIRST_DIRECTION[column];\n  }\n  if (sort.direction === 'asc') {\n    return 'desc';\n  }\n  return 'asc';\n}\n\nfunction sorted(state: AccountsState, column: SortColumn): AccountsState {\n  const direction = directionAfter(state.sort, column);\n  const spoken = `Sorted by ${SORT_LABEL[column]}, ${DIRECTION_WORD[direction]}`;\n  return {\n    ...state,\n    sort: { column, direction },\n    page: 0,\n    streamingSummary: null,\n    revision: state.revision + 1,\n    spoken,\n  };\n}\n\nfunction pageTurned(state: AccountsState, target: number): AccountsState {\n  const result = resultOfState(state);\n  const pageCount = pageCountOf(result.length);\n  const lastPage = pageCount - 1;\n  const atLeastFirst = Math.max(0, target);\n  const page = Math.min(lastPage, atLeastFirst);\n  if (page === state.page) {\n    return state;\n  }\n  return {\n    ...state,\n    page,\n    streamingSummary: null,\n    revision: state.revision + 1,\n    spoken: `Page ${page + 1} of ${pageCount}`,\n  };\n}\n\nfunction selectedLineOf(count: number) {\n  if (count === 0) {\n    return 'Nothing selected';\n  }\n  return `${count} selected`;\n}\n\nfunction withSelection(state: AccountsState, selected: string[]) {\n  return {\n    ...state,\n    selected,\n    bulkMode: bulkModeFor(selected, state.bulkMode),\n    spoken: selectedLineOf(selected.length),\n  };\n}\n\nfunction rowToggled(state: AccountsState, id: string): AccountsState {\n  const isSelected = state.selected.includes(id);\n  if (isSelected) {\n    const selected = state.selected.filter((candidate) => candidate !== id);\n    return withSelection(state, selected);\n  }\n  return withSelection(state, [...state.selected, id]);\n}\n\n/** The box of the header selects the rows of the page, or lets go of them when they all are. */\nfunction pageToggled(state: AccountsState): AccountsState {\n  const rows = pageRowsOf(resultOfState(state), state.page);\n  const pageIds = rows.map((account) => account.id);\n  if (pageIds.length === 0) {\n    return state;\n  }\n  const isPageSelected = pageIds.every((id) => state.selected.includes(id));\n  if (isPageSelected) {\n    const selected = state.selected.filter((id) => !pageIds.includes(id));\n    return withSelection(state, selected);\n  }\n  const missing = pageIds.filter((id) => !state.selected.includes(id));\n  return withSelection(state, [...state.selected, ...missing]);\n}\n\nfunction ownerAssigned(state: AccountsState, owner: OwnerId): AccountsState {\n  const count = state.selected.length;\n  if (count === 0) {\n    return state;\n  }\n  const owners: Owners = { ...state.owners };\n  for (const id of state.selected) {\n    owners[id] = owner;\n  }\n  const spoken = `${countLineOf(count)} assigned to ${ownerOf(owner).name}`;\n  return { ...state, owners, selected: [], bulkMode: 'actions', spoken };\n}\n\nfunction summaryToggled(state: AccountsState, id: string): AccountsState {\n  const isOpen = state.openSummaries.includes(id);\n  if (isOpen) {\n    const openSummaries = state.openSummaries.filter(\n      (candidate) => candidate !== id\n    );\n    return { ...state, openSummaries, streamingSummary: null, spoken: '' };\n  }\n  const account = accountOf(id);\n  const openSummaries = [...state.openSummaries, id];\n  const spoken = `${account.name}: ${summaryOf(account)}`;\n  const isWritten = state.writtenSummaries.includes(id);\n  if (isWritten) {\n    return { ...state, openSummaries, streamingSummary: null, spoken };\n  }\n  return {\n    ...state,\n    openSummaries,\n    writtenSummaries: [...state.writtenSummaries, id],\n    streamingSummary: id,\n    spoken,\n  };\n}\n\nexport function reducer(\n  state: AccountsState,\n  action: AccountsAction\n): AccountsState {\n  switch (action.type) {\n    case 'questionTyped':\n      return { ...state, question: action.text, hasAskFailed: false };\n    case 'asked':\n      return asked(state);\n    case 'filterRemoved':\n      return filterRemoved(state, action.kind);\n    case 'filtersCleared':\n      return filtersCleared(state);\n    case 'viewPicked':\n      return viewPicked(state, action.view);\n    case 'sorted':\n      return sorted(state, action.column);\n    case 'pageTurned':\n      return pageTurned(state, action.page);\n    case 'rowToggled':\n      return rowToggled(state, action.id);\n    case 'pageToggled':\n      return pageToggled(state);\n    case 'selectionCleared':\n      return withSelection(state, []);\n    case 'bulkModeSet':\n      return { ...state, bulkMode: bulkModeFor(state.selected, action.mode) };\n    case 'ownerAssigned':\n      return ownerAssigned(state, action.owner);\n    case 'exported': {\n      const spoken = `${countLineOf(state.selected.length)} exported`;\n      return { ...state, spoken };\n    }\n    case 'summaryToggled':\n      return summaryToggled(state, action.id);\n  }\n}\n\nconst KEY_MS = 45;\n\nfunction typingSteps(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((typed, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'questionTyped', text: typed },\n  }));\n}\n\n/** The two enterprise accounts of Europe that renew this quarter, and the one summarised at the end. */\nconst FIRST_ROW = 'greyfriars-bank';\n\nconst SECOND_ROW = 'halden-works';\n\n/**\n * A person does everything here, so every step is the demonstration's: a question becomes three\n * chips, one is taken off, the two accounts that renew this quarter get a new owner, then the\n * largest one is summarised.\n */\nexport const SCRIPT: Step[] = [\n  ...typingSteps(ASK_EXAMPLE, 1200),\n  { after: 500, by: 'demo', press: 'ask', action: { type: 'asked' } },\n  {\n    after: 1900,\n    by: 'demo',\n    press: 'chip-seatsOver',\n    action: { type: 'filterRemoved', kind: 'seatsOver' },\n  },\n  {\n    after: 1700,\n    by: 'demo',\n    press: 'view-renewing',\n    action: { type: 'viewPicked', view: 'renewing' },\n  },\n  {\n    after: 1400,\n    by: 'demo',\n    press: `select-${FIRST_ROW}`,\n    action: { type: 'rowToggled', id: FIRST_ROW },\n  },\n  {\n    after: 650,\n    by: 'demo',\n    press: `select-${SECOND_ROW}`,\n    action: { type: 'rowToggled', id: SECOND_ROW },\n  },\n  {\n    after: 1300,\n    by: 'demo',\n    press: 'assign',\n    action: { type: 'bulkModeSet', mode: 'owners' },\n  },\n  {\n    after: 1100,\n    by: 'demo',\n    press: 'owner-priya',\n    action: { type: 'ownerAssigned', owner: 'priya' },\n  },\n  {\n    after: 1600,\n    by: 'demo',\n    press: 'view-all',\n    action: { type: 'viewPicked', view: 'all' },\n  },\n  {\n    after: 1400,\n    by: 'demo',\n    press: 'sort-seats',\n    action: { type: 'sorted', column: 'seats' },\n  },\n  {\n    after: 1500,\n    by: 'demo',\n    press: `summarize-${FIRST_ROW}`,\n    action: { type: 'summaryToggled', id: FIRST_ROW },\n  },\n];\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\n/**\n * Under reduced motion the table rests where the script ends: two chips, the five accounts sorted\n * by seats, two of them with their new owner, and the summary of the first one written out.\n */\nexport const RESTING: AccountsState = {\n  ...endOf(SCRIPT),\n  streamingSummary: null,\n  spoken: '',\n};\n\n/** The summary takes about two seconds to arrive, then the table is left to read. */\nexport const LOOP_AFTER_MS = 5600;\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/ai-data/ai-data-01/data.ts",
      "content": "export type PlanId = 'starter' | 'team' | 'business' | 'enterprise';\n\nexport type RegionId =\n  'europe' | 'north-america' | 'asia-pacific' | 'latin-america';\n\nexport type Health = 'healthy' | 'watch' | 'risk';\n\nexport type OwnerId = 'maya' | 'jonas' | 'priya' | 'tomas';\n\nexport type Owner = {\n  id: OwnerId;\n  name: string;\n  firstName: string;\n};\n\nexport const OWNERS: Owner[] = [\n  { id: 'maya', name: 'Maya Okafor', firstName: 'Maya' },\n  { id: 'jonas', name: 'Jonas Weber', firstName: 'Jonas' },\n  { id: 'priya', name: 'Priya Nair', firstName: 'Priya' },\n  { id: 'tomas', name: 'Tomas Rivera', firstName: 'Tomas' },\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 const PLANS: PlanId[] = ['starter', 'team', 'business', 'enterprise'];\n\nexport const PLAN_LABEL: Record<PlanId, string> = {\n  starter: 'Starter',\n  team: 'Team',\n  business: 'Business',\n  enterprise: 'Enterprise',\n};\n\n/** Plans sort by size, not by letter. */\nexport const PLAN_RANK: Record<PlanId, number> = {\n  starter: 0,\n  team: 1,\n  business: 2,\n  enterprise: 3,\n};\n\nexport const REGIONS: RegionId[] = [\n  'europe',\n  'north-america',\n  'asia-pacific',\n  'latin-america',\n];\n\nexport const REGION_LABEL: Record<RegionId, string> = {\n  europe: 'Europe',\n  'north-america': 'North America',\n  'asia-pacific': 'Asia Pacific',\n  'latin-america': 'Latin America',\n};\n\nexport const HEALTH_LABEL: Record<Health, string> = {\n  healthy: 'Healthy',\n  watch: 'Watch',\n  risk: 'At risk',\n};\n\nexport type Account = {\n  id: string;\n  name: string;\n  plan: PlanId;\n  region: RegionId;\n  seats: number;\n  /** Seats added or removed since last quarter. */\n  seatsDelta: number;\n  /** The day the contract renews, as an ISO day. */\n  renewal: string;\n  health: Health;\n  owner: OwnerId;\n  /** What the account team noticed last, as one plain fact. */\n  signal: string;\n};\n\n/** The day the sample data is read on. A fixed day keeps the server and the browser on the same page. */\nconst TODAY = '2026-11-12';\n\nconst QUARTER_END = '2026-12-31';\n\nconst THIS_YEAR = '2026';\n\nexport const TODAY_LABEL = 'Nov 12';\n\n/** Invented companies, seats and dates. The figures are illustrative. */\nexport const ACCOUNTS: Account[] = [\n  {\n    id: 'halden-works',\n    name: 'Halden Works',\n    plan: 'enterprise',\n    region: 'europe',\n    seats: 320,\n    seatsDelta: 24,\n    renewal: '2026-12-04',\n    health: 'healthy',\n    owner: 'maya',\n    signal: 'Their admin asked about audit logs in October',\n  },\n  {\n    id: 'norhaven-freight',\n    name: 'Norhaven Freight',\n    plan: 'business',\n    region: 'north-america',\n    seats: 84,\n    seatsDelta: -6,\n    renewal: '2027-03-18',\n    health: 'watch',\n    owner: 'jonas',\n    signal: 'Usage dropped after two dispatchers left in September',\n  },\n  {\n    id: 'solway-books',\n    name: 'Solway Books',\n    plan: 'team',\n    region: 'europe',\n    seats: 26,\n    seatsDelta: 3,\n    renewal: '2026-11-30',\n    health: 'healthy',\n    owner: 'priya',\n    signal: 'They opened one ticket this quarter, solved the same day',\n  },\n  {\n    id: 'kestrel-labs',\n    name: 'Kestrel Labs',\n    plan: 'enterprise',\n    region: 'europe',\n    seats: 140,\n    seatsDelta: -18,\n    renewal: '2027-02-09',\n    health: 'risk',\n    owner: 'maya',\n    signal: 'Weekly logins fell by a third since their reorganisation',\n  },\n  {\n    id: 'marlow-finch',\n    name: 'Marlow & Finch',\n    plan: 'starter',\n    region: 'europe',\n    seats: 8,\n    seatsDelta: 0,\n    renewal: '2027-05-21',\n    health: 'healthy',\n    owner: 'tomas',\n    signal: 'They are still on the first project they created',\n  },\n  {\n    id: 'brightwell-health',\n    name: 'Brightwell Health',\n    plan: 'enterprise',\n    region: 'north-america',\n    seats: 410,\n    seatsDelta: 40,\n    renewal: '2026-12-15',\n    health: 'watch',\n    owner: 'jonas',\n    signal: 'A second department is waiting on a security review',\n  },\n  {\n    id: 'pallas-robotics',\n    name: 'Pallas Robotics',\n    plan: 'business',\n    region: 'asia-pacific',\n    seats: 96,\n    seatsDelta: 12,\n    renewal: '2027-01-27',\n    health: 'healthy',\n    owner: 'priya',\n    signal: 'Their team built nine automations last month',\n  },\n  {\n    id: 'verano-foods',\n    name: 'Verano Foods',\n    plan: 'team',\n    region: 'latin-america',\n    seats: 34,\n    seatsDelta: -9,\n    renewal: '2026-12-22',\n    health: 'risk',\n    owner: 'tomas',\n    signal: 'Two invoices were paid late this year',\n  },\n  {\n    id: 'tidemark-energy',\n    name: 'Tidemark Energy',\n    plan: 'enterprise',\n    region: 'europe',\n    seats: 88,\n    seatsDelta: 4,\n    renewal: '2027-04-02',\n    health: 'healthy',\n    owner: 'maya',\n    signal: 'They asked for a quote on 40 more seats',\n  },\n  {\n    id: 'quillon-legal',\n    name: 'Quillon Legal',\n    plan: 'business',\n    region: 'europe',\n    seats: 62,\n    seatsDelta: -11,\n    renewal: '2026-11-19',\n    health: 'risk',\n    owner: 'priya',\n    signal: 'Their champion moved to another firm in August',\n  },\n  {\n    id: 'aster-studio',\n    name: 'Aster Studio',\n    plan: 'starter',\n    region: 'north-america',\n    seats: 5,\n    seatsDelta: 0,\n    renewal: '2027-06-11',\n    health: 'healthy',\n    owner: 'jonas',\n    signal: 'Both founders log in every day',\n  },\n  {\n    id: 'lumiere-travel',\n    name: 'Lumiere Travel',\n    plan: 'team',\n    region: 'europe',\n    seats: 41,\n    seatsDelta: -4,\n    renewal: '2027-01-14',\n    health: 'watch',\n    owner: 'maya',\n    signal: 'Seasonal staff left and their seats were not removed',\n  },\n  {\n    id: 'corvid-security',\n    name: 'Corvid Security',\n    plan: 'enterprise',\n    region: 'asia-pacific',\n    seats: 230,\n    seatsDelta: 30,\n    renewal: '2027-03-05',\n    health: 'healthy',\n    owner: 'priya',\n    signal: 'They rolled out to their Sydney office this quarter',\n  },\n  {\n    id: 'fennel-market',\n    name: 'Fennel Market',\n    plan: 'starter',\n    region: 'latin-america',\n    seats: 12,\n    seatsDelta: 2,\n    renewal: '2027-02-24',\n    health: 'watch',\n    owner: 'tomas',\n    signal: 'The owner has not logged in for three weeks',\n  },\n  {\n    id: 'greyfriars-bank',\n    name: 'Greyfriars Bank',\n    plan: 'enterprise',\n    region: 'europe',\n    seats: 540,\n    seatsDelta: -35,\n    renewal: '2026-12-11',\n    health: 'risk',\n    owner: 'maya',\n    signal: 'Their procurement team asked for the contract terms twice',\n  },\n  {\n    id: 'ironbridge-tools',\n    name: 'Ironbridge Tools',\n    plan: 'business',\n    region: 'north-america',\n    seats: 118,\n    seatsDelta: 9,\n    renewal: '2027-05-08',\n    health: 'healthy',\n    owner: 'jonas',\n    signal: 'They renewed a month early last year',\n  },\n  {\n    id: 'rowan-clinics',\n    name: 'Rowan Clinics',\n    plan: 'team',\n    region: 'asia-pacific',\n    seats: 29,\n    seatsDelta: 5,\n    renewal: '2026-12-29',\n    health: 'healthy',\n    owner: 'priya',\n    signal: 'Three clinics were added since spring',\n  },\n  {\n    id: 'larkspur-media',\n    name: 'Larkspur Media',\n    plan: 'business',\n    region: 'europe',\n    seats: 73,\n    seatsDelta: 7,\n    renewal: '2027-04-19',\n    health: 'healthy',\n    owner: 'tomas',\n    signal: 'Editors use it daily, the sales team barely at all',\n  },\n  {\n    id: 'heron-logistics',\n    name: 'Heron Logistics',\n    plan: 'enterprise',\n    region: 'latin-america',\n    seats: 164,\n    seatsDelta: -14,\n    renewal: '2027-01-06',\n    health: 'watch',\n    owner: 'tomas',\n    signal: 'Another vendor ran a pilot with their operations team',\n  },\n  {\n    id: 'pemberton-schools',\n    name: 'Pemberton Schools',\n    plan: 'team',\n    region: 'north-america',\n    seats: 48,\n    seatsDelta: 6,\n    renewal: '2027-03-29',\n    health: 'healthy',\n    owner: 'jonas',\n    signal: 'Usage follows the school calendar and is back up',\n  },\n  {\n    id: 'rookery-games',\n    name: 'Rookery Games',\n    plan: 'starter',\n    region: 'asia-pacific',\n    seats: 9,\n    seatsDelta: -3,\n    renewal: '2026-11-25',\n    health: 'risk',\n    owner: 'priya',\n    signal: 'The card on file expired in October',\n  },\n  {\n    id: 'saltmarsh-hotels',\n    name: 'Saltmarsh Hotels',\n    plan: 'business',\n    region: 'europe',\n    seats: 104,\n    seatsDelta: 10,\n    renewal: '2027-06-02',\n    health: 'watch',\n    owner: 'maya',\n    signal: 'They asked how to add a second workspace',\n  },\n  {\n    id: 'thornbury-insurance',\n    name: 'Thornbury Insurance',\n    plan: 'enterprise',\n    region: 'europe',\n    seats: 275,\n    seatsDelta: 21,\n    renewal: '2027-02-17',\n    health: 'healthy',\n    owner: 'jonas',\n    signal: 'Their compliance team signed off on the data policy',\n  },\n  {\n    id: 'wexford-dairy',\n    name: 'Wexford Dairy',\n    plan: 'team',\n    region: 'europe',\n    seats: 22,\n    seatsDelta: 1,\n    renewal: '2027-04-27',\n    health: 'healthy',\n    owner: 'priya',\n    signal: 'One person does all the work in it',\n  },\n];\n\nconst FALLBACK_ACCOUNT = ACCOUNTS[0];\n\nexport function accountOf(id: string) {\n  const account = ACCOUNTS.find((candidate) => candidate.id === id);\n  return account ?? FALLBACK_ACCOUNT;\n}\n\n/** A renewal still to come before the quarter ends. ISO days compare as text. */\nexport function renewsThisQuarter(account: Account) {\n  const isStillAhead = account.renewal >= TODAY;\n  const isBeforeQuarterEnd = account.renewal <= QUARTER_END;\n  return isStillAhead && isBeforeQuarterEnd;\n}\n\n/** A fixed time zone, so a day never shifts between the server and the browser. */\nconst DAY_FORMAT = new Intl.DateTimeFormat('en-US', {\n  month: 'short',\n  day: 'numeric',\n  timeZone: 'UTC',\n});\n\nconst DAY_AND_YEAR_FORMAT = new Intl.DateTimeFormat('en-US', {\n  month: 'short',\n  day: 'numeric',\n  year: 'numeric',\n  timeZone: 'UTC',\n});\n\n/** Dec 4 this year, Mar 18, 2027 after it. */\nexport function renewalLabelOf(renewal: string) {\n  const day = new Date(`${renewal}T00:00:00Z`);\n  const isThisYear = renewal.startsWith(THIS_YEAR);\n  if (isThisYear) {\n    return DAY_FORMAT.format(day);\n  }\n  return DAY_AND_YEAR_FORMAT.format(day);\n}\n\nfunction seatsChangeOf(delta: number) {\n  if (delta > 0) {\n    return `${delta} more than last quarter`;\n  }\n  if (delta < 0) {\n    return `${Math.abs(delta)} fewer than last quarter`;\n  }\n  return 'the same as last quarter';\n}\n\nfunction nextStepOf(account: Account) {\n  const day = renewalLabelOf(account.renewal);\n  const isSoon = renewsThisQuarter(account);\n  const isAtRisk = account.health === 'risk';\n  if (isAtRisk && isSoon) {\n    return `It renews on ${day}: call them before then.`;\n  }\n  if (isAtRisk) {\n    return `Worth a call well before it renews on ${day}.`;\n  }\n  if (account.health === 'watch') {\n    return `Keep an eye on it until it renews on ${day}.`;\n  }\n  if (isSoon) {\n    return `It renews on ${day}, a good moment to offer the yearly plan.`;\n  }\n  return `Nothing to do before it renews on ${day}.`;\n}\n\n/** Three sentences written from the fields of the row. No model is called. */\nexport function summaryOf(account: Account) {\n  const plan = PLAN_LABEL[account.plan];\n  const change = seatsChangeOf(account.seatsDelta);\n  const facts = `${account.name} is on ${plan} with ${account.seats} seats, ${change}.`;\n  const nextStep = nextStepOf(account);\n  return `${facts} ${account.signal}. ${nextStep}`;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-data-01/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "ai-data"
  ],
  "type": "registry:block"
}