{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "prompt-03",
  "title": "Model picker",
  "description": "Models grouped by lab with context, speed, price and skills, searched and picked from the keyboard, with a compare view that widens the panel.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/drawn-check.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/popover.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.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/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/prompt/prompt-03.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport {\n  useId,\n  useImperativeHandle,\n  useRef,\n  useState,\n  useSyncExternalStore,\n} from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport {\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  hold,\n  keyDelayOf,\n  prefixesOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  CheckIcon,\n  ChevronsUpDownIcon,\n  MinusIcon,\n  SearchIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { MENU_LABEL } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport {\n  Dialog,\n  DialogContent,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTitle,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\nimport { Switch } from '@/registry/ndeko/ui/switch';\n\nimport { LabTile } from './_parts/lab-tile';\nimport {\n  CAPABILITIES,\n  CAPABILITY_LABEL,\n  contextLabelOf,\n  labOf,\n  LABS,\n  MODELS,\n  modelOf,\n  PRICE_WORD,\n  SPEED_WORD,\n  type Lab,\n  type ModelOption,\n  type Tier,\n} from './_parts/labs';\nimport { includesQuery, Marked } from './_parts/marked';\n\n/** `inline` draws the panel in the page under its trigger, with no layer to open. */\nexport type PickerSurface = 'popover' | 'dialog' | 'inline';\n\nexport type ModelPickerHandle = {\n  /** Moves the highlight by rows, as the arrow keys do. */\n  move: (step: number) => void;\n  /** Puts the highlight on a model, as the pointer does. */\n  highlight: (modelId: string) => void;\n  search: (query: string) => void;\n  /** Picks the highlighted model, as Enter does. */\n  pickHighlighted: () => void;\n  compare: (isComparing: boolean) => void;\n};\n\n/** Quicker than a tab thumb: the highlight follows the pointer from row to row. */\nconst HIGHLIGHT_TRAVEL = { type: 'spring', bounce: 0, duration: 0.22 } as const;\n\nconst NO_TRAVEL = { duration: 0 };\n\nfunction highlightTravelOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return NO_TRAVEL;\n  }\n  return HIGHLIGHT_TRAVEL;\n}\n\nconst WIDE_QUERY = '(min-width: 640px)';\n\nconst TIERS: Tier[] = [1, 2, 3];\n\nconst SPEED_BAR_HEIGHT: Record<Tier, string> = {\n  1: 'h-1.5',\n  2: 'h-2.5',\n  3: 'h-3.5',\n};\n\nfunction subscribeToWidth(listener: () => void) {\n  const query = window.matchMedia(WIDE_QUERY);\n  query.addEventListener('change', listener);\n  return () => query.removeEventListener('change', listener);\n}\n\nfunction isWideNow() {\n  return window.matchMedia(WIDE_QUERY).matches;\n}\n\nfunction isWideOnServer() {\n  return true;\n}\n\nfunction surfaceOf(as: PickerSurface | undefined, isWide: boolean) {\n  if (as) {\n    return as;\n  }\n  if (isWide) {\n    return 'popover';\n  }\n  return 'dialog';\n}\n\nfunction barToneOf(isFilled: boolean) {\n  if (isFilled) {\n    return 'bg-foreground/70';\n  }\n  return 'bg-foreground/15';\n}\n\nfunction SpeedBars({ speed }: { speed: Tier }) {\n  return (\n    <span className='inline-flex items-center gap-1'>\n      <span aria-hidden='true' className='flex h-3.5 items-end gap-px'>\n        {TIERS.map((tier) => (\n          <span\n            key={tier}\n            className={cn(\n              'w-[3px] rounded-[1px]',\n              SPEED_BAR_HEIGHT[tier],\n              barToneOf(tier <= speed)\n            )}\n          />\n        ))}\n      </span>\n      <span className='sr-only'>{SPEED_WORD[speed]}</span>\n    </span>\n  );\n}\n\nfunction priceToneOf(isPaid: boolean) {\n  if (isPaid) {\n    return 'text-foreground/80';\n  }\n  return 'text-foreground/20';\n}\n\nfunction PriceMarks({ price }: { price: Tier }) {\n  return (\n    <span className='inline-flex font-mono text-[11px] leading-none'>\n      <span aria-hidden='true'>\n        {TIERS.map((tier) => (\n          <span key={tier} className={priceToneOf(tier <= price)}>\n            $\n          </span>\n        ))}\n      </span>\n      <span className='sr-only'>{PRICE_WORD[price]}</span>\n    </span>\n  );\n}\n\nfunction CapabilityChips({ model }: { model: ModelOption }) {\n  return (\n    <span className='flex flex-wrap gap-1'>\n      {model.capabilities.map((capability) => (\n        <Badge\n          key={capability}\n          variant='secondary'\n          className='h-[18px] px-1.5 text-[11px] font-normal'\n        >\n          {CAPABILITY_LABEL[capability]}\n        </Badge>\n      ))}\n    </span>\n  );\n}\n\nfunction ModelFacts({ model }: { model: ModelOption }) {\n  const context = contextLabelOf(model.contextTokens);\n\n  return (\n    <span className='text-muted-foreground flex flex-wrap items-center gap-x-2.5 gap-y-1 text-xs'>\n      <span className='tabular-nums'>\n        {context}\n        <span className='sr-only'> tokens of context</span>\n      </span>\n      <SpeedBars speed={model.speed} />\n      <PriceMarks price={model.price} />\n    </span>\n  );\n}\n\nfunction matchesModel(model: ModelOption, query: string) {\n  const lab = labOf(model.lab);\n  const capabilityWords = model.capabilities.map(\n    (capability) => CAPABILITY_LABEL[capability]\n  );\n  const words = [model.name, lab.name, ...capabilityWords];\n  const text = words.join(' ');\n  return includesQuery(text, query);\n}\n\ntype ModelGroup = {\n  lab: Lab;\n  models: ModelOption[];\n};\n\nfunction groupsOf(models: ModelOption[]) {\n  const groups: ModelGroup[] = [];\n  for (const lab of LABS) {\n    const fromLab = models.filter((model) => model.lab === lab.id);\n    if (fromLab.length > 0) {\n      groups.push({ lab, models: fromLab });\n    }\n  }\n  return groups;\n}\n\nfunction flatOf(groups: ModelGroup[]) {\n  const flat: ModelOption[] = [];\n  for (const group of groups) {\n    flat.push(...group.models);\n  }\n  return flat;\n}\n\nfunction stepIndex(current: number, step: number, count: number) {\n  const moved = current + step;\n  const wrapped = moved + count;\n  return wrapped % count;\n}\n\n/** Scrolls the list itself: scrollIntoView could move the whole page. */\nfunction keepInView(list: HTMLElement | null, optionId: string) {\n  if (!list) {\n    return;\n  }\n  const option = document.getElementById(optionId);\n  if (!option) {\n    return;\n  }\n  const top = option.offsetTop;\n  const bottom = top + option.offsetHeight;\n  const viewBottom = list.scrollTop + list.clientHeight;\n  if (top < list.scrollTop) {\n    list.scrollTop = top;\n    return;\n  }\n  if (bottom > viewBottom) {\n    list.scrollTop = bottom - list.clientHeight;\n  }\n}\n\nfunction compareOtherOf(\n  active: ModelOption | undefined,\n  picked: ModelOption,\n  visible: ModelOption[]\n) {\n  const isOther = active !== undefined && active.id !== picked.id;\n  if (isOther) {\n    return active;\n  }\n  return visible.find((model) => model.id !== picked.id);\n}\n\nfunction HasMark({ has, label }: { has: boolean; label: string }) {\n  if (has) {\n    return (\n      <span className='text-success-foreground inline-flex'>\n        <CheckIcon className='size-3.5' strokeWidth={2.25} />\n        <span className='sr-only'>{label}: yes</span>\n      </span>\n    );\n  }\n  return (\n    <span className='text-muted-foreground/50 inline-flex'>\n      <MinusIcon className='size-3.5' />\n      <span className='sr-only'>{label}: no</span>\n    </span>\n  );\n}\n\ntype CompareTableProps = {\n  picked: ModelOption;\n  other: ModelOption | undefined;\n};\n\nexport function CompareTable({ picked, other }: CompareTableProps) {\n  const columns = [picked];\n  if (other) {\n    columns.push(other);\n  }\n\n  return (\n    <table className='w-full table-fixed text-xs'>\n      <caption className='sr-only'>\n        Compare {picked.name} with {other?.name ?? 'another model'}\n      </caption>\n      <thead>\n        <tr>\n          <th scope='col' className='w-24 pb-2 text-start font-normal'>\n            <span className='sr-only'>Fact</span>\n          </th>\n          {columns.map((model, index) => (\n            <th\n              key={index}\n              scope='col'\n              className='pb-2 text-start align-bottom font-medium'\n            >\n              <span className='text-muted-foreground block text-[11px] font-normal'>\n                {index === 0 && 'Current'}\n                {index === 1 && 'Looking at'}\n              </span>\n              <span className='flex items-center gap-1.5'>\n                <LabTile lab={model.lab} size='sm' />\n                <span className='truncate'>\n                  <Swap swapKey={model.id}>{model.name}</Swap>\n                </span>\n              </span>\n            </th>\n          ))}\n        </tr>\n      </thead>\n      <tbody className='text-muted-foreground'>\n        <tr className='h-7'>\n          <th scope='row' className='text-start font-normal'>\n            Context\n          </th>\n          {columns.map((model, index) => (\n            <td key={index} className='text-foreground tabular-nums'>\n              {contextLabelOf(model.contextTokens)}\n            </td>\n          ))}\n        </tr>\n        <tr className='h-7'>\n          <th scope='row' className='text-start font-normal'>\n            Speed\n          </th>\n          {columns.map((model, index) => (\n            <td key={index}>\n              <SpeedBars speed={model.speed} />\n            </td>\n          ))}\n        </tr>\n        <tr className='h-7'>\n          <th scope='row' className='text-start font-normal'>\n            Price\n          </th>\n          {columns.map((model, index) => (\n            <td key={index}>\n              <PriceMarks price={model.price} />\n            </td>\n          ))}\n        </tr>\n        {CAPABILITIES.map((capability) => (\n          <tr key={capability} className='h-7'>\n            <th scope='row' className='text-start font-normal'>\n              {CAPABILITY_LABEL[capability]}\n            </th>\n            {columns.map((model, index) => (\n              <td key={index}>\n                <HasMark\n                  has={model.capabilities.includes(capability)}\n                  label={CAPABILITY_LABEL[capability]}\n                />\n              </td>\n            ))}\n          </tr>\n        ))}\n      </tbody>\n    </table>\n  );\n}\n\nfunction resultsLineOf(count: number, query: string) {\n  const trimmed = query.trim();\n  if (trimmed === '') {\n    return '';\n  }\n  if (count === 0) {\n    return `No model matches “${trimmed}”`;\n  }\n  return countOf(count, 'model');\n}\n\nfunction panelWidthOf(isComparing: boolean, layout: PickerSurface) {\n  const isSide = layout === 'popover';\n  if (!isSide) {\n    return 'w-full';\n  }\n  if (isComparing) {\n    return 'w-[40rem] max-w-[calc(100vw-2rem)]';\n  }\n  return 'w-[22rem] max-w-[calc(100vw-2rem)]';\n}\n\ntype ModelPanelProps = {\n  models: ModelOption[];\n  pickedId: string;\n  onPick: (modelId: string) => void;\n  layout: PickerSurface;\n  searchRef: React.RefObject<HTMLInputElement | null>;\n  handleRef?: React.Ref<ModelPickerHandle>;\n  isDemonstrated: boolean;\n};\n\nfunction ModelPanel({\n  models,\n  pickedId,\n  onPick,\n  layout,\n  searchRef,\n  handleRef,\n  isDemonstrated,\n}: ModelPanelProps) {\n  const [query, setQuery] = useState('');\n  const [activeId, setActiveId] = useState(pickedId);\n  const [isComparing, setIsComparing] = useState(false);\n  const listRef = useRef<HTMLDivElement>(null);\n  const baseId = useId();\n  const listId = `${baseId}-list`;\n  const picked = modelOf(pickedId);\n  const matching = models.filter((model) => matchesModel(model, query));\n  const groups = groupsOf(matching);\n  const visible = flatOf(groups);\n  const active = visible.find((model) => model.id === activeId) ?? visible[0];\n  const activeOptionId = optionIdOf(baseId, active?.id);\n  const other = compareOtherOf(active, picked, visible);\n  const isEmpty = visible.length === 0;\n  const results = resultsLineOf(visible.length, query);\n  const isSide = layout === 'popover';\n  const hasCloseButton = layout === 'dialog';\n\n  function pickHighlighted() {\n    if (active) {\n      onPick(active.id);\n    }\n  }\n\n  function optionIdFor(modelId: string) {\n    return optionIdOf(baseId, modelId) ?? '';\n  }\n\n  function moveActive(step: number) {\n    if (isEmpty) {\n      return;\n    }\n    const currentIndex = visible.findIndex((model) => model.id === active?.id);\n    const nextIndex = stepIndex(currentIndex, step, visible.length);\n    const next = visible[nextIndex];\n    setActiveId(next.id);\n    keepInView(listRef.current, optionIdFor(next.id));\n  }\n\n  function handleSearchKeys(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key === 'ArrowDown') {\n      event.preventDefault();\n      moveActive(1);\n      return;\n    }\n    if (event.key === 'ArrowUp') {\n      event.preventDefault();\n      moveActive(-1);\n      return;\n    }\n    if (event.key === 'Enter') {\n      event.preventDefault();\n      pickHighlighted();\n    }\n  }\n\n  function changeQuery(next: string) {\n    setQuery(next);\n    listRef.current?.scrollTo({ top: 0 });\n  }\n\n  function clearSearch() {\n    setQuery('');\n    searchRef.current?.focus();\n  }\n\n  useImperativeHandle(handleRef, () => ({\n    move: moveActive,\n    highlight: setActiveId,\n    search: changeQuery,\n    pickHighlighted,\n    compare: setIsComparing,\n  }));\n\n  return (\n    <AnimatedSize axis={sizeAxisOf(layout)}>\n      <div className={cn('flex flex-col', panelWidthOf(isComparing, layout))}>\n        <div\n          className={cn(\n            'flex items-center justify-between gap-3 px-3 pt-3 pb-2',\n            hasCloseButton && 'pe-12'\n          )}\n        >\n          <p className='text-sm font-medium'>Choose a model</p>\n          <label className='text-muted-foreground flex cursor-pointer items-center gap-2 text-xs'>\n            Compare\n            <Switch\n              checked={isComparing}\n              onCheckedChange={(checked) => setIsComparing(checked)}\n            />\n          </label>\n        </div>\n        <div className='relative px-3 pb-2'>\n          <SearchIcon className='text-muted-foreground pointer-events-none absolute start-5.5 top-4 size-4 -translate-y-1/2' />\n          <Input\n            ref={searchRef}\n            role='combobox'\n            aria-expanded='true'\n            aria-controls={listId}\n            aria-activedescendant={activeOptionId}\n            aria-autocomplete='list'\n            aria-label='Search models'\n            value={query}\n            onChange={(event) => changeQuery(event.target.value)}\n            onKeyDown={handleSearchKeys}\n            placeholder='Search by name, lab or skill'\n            className='ps-8'\n          />\n        </div>\n        <div className={cn('flex min-h-0', !isSide && 'flex-col')}>\n          <div className='min-w-0 flex-1'>\n            <div\n              ref={listRef}\n              id={listId}\n              role='listbox'\n              aria-label='Models'\n              className='relative max-h-72 overflow-y-auto px-1.5 pb-1.5'\n            >\n              {groups.map((group) => (\n                <ModelGroupRows\n                  key={group.lab.id}\n                  group={group}\n                  baseId={baseId}\n                  pickedId={pickedId}\n                  activeId={active?.id}\n                  query={query}\n                  onActivate={setActiveId}\n                  onPick={onPick}\n                />\n              ))}\n              {isEmpty && (\n                <div className='flex flex-col items-center gap-2 px-4 py-6 text-center'>\n                  <p className='text-muted-foreground text-[13px]'>{results}</p>\n                  <Button\n                    type='button'\n                    variant='outline'\n                    size='sm'\n                    onClick={clearSearch}\n                  >\n                    <XIcon />\n                    Clear the search\n                  </Button>\n                </div>\n              )}\n            </div>\n          </div>\n          {isComparing && (\n            <div\n              className={cn(\n                'bg-foreground/[0.025] dark:bg-foreground/[0.04] m-1.5 mt-0 rounded-lg p-3',\n                isSide && 'w-[17rem] shrink-0 self-start'\n              )}\n            >\n              <CompareTable picked={picked} other={other} />\n            </div>\n          )}\n        </div>\n        <p className='text-muted-foreground px-3 pt-1 pb-3 text-[11px]'>\n          Context, speed and price are illustrative\n        </p>\n      </div>\n      <LiveRegion message={spokenUnless(isDemonstrated, results)} />\n    </AnimatedSize>\n  );\n}\n\n/** In a dialog the width belongs to the dialog; only a popover grows sideways for Compare. */\nfunction sizeAxisOf(layout: PickerSurface) {\n  if (layout === 'popover') {\n    return 'both';\n  }\n  return 'height';\n}\n\nfunction optionIdOf(baseId: string, modelId: string | undefined) {\n  if (!modelId) {\n    return undefined;\n  }\n  return `${baseId}-option-${modelId}`;\n}\n\ntype ModelGroupRowsProps = {\n  group: ModelGroup;\n  baseId: string;\n  pickedId: string;\n  activeId: string | undefined;\n  query: string;\n  onActivate: (modelId: string) => void;\n  onPick: (modelId: string) => void;\n};\n\nfunction ModelGroupRows({\n  group,\n  baseId,\n  pickedId,\n  activeId,\n  query,\n  onActivate,\n  onPick,\n}: ModelGroupRowsProps) {\n  const headingId = `${baseId}-lab-${group.lab.id}`;\n  const highlightId = `${baseId}-highlight`;\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travel = highlightTravelOf(shouldReduceMotion);\n\n  return (\n    <div role='group' aria-labelledby={headingId}>\n      <p id={headingId} className={cn(MENU_LABEL, 'flex items-center gap-1.5')}>\n        <LabTile lab={group.lab.id} size='sm' />\n        {group.lab.name}\n      </p>\n      {group.models.map((model) => {\n        const isPicked = model.id === pickedId;\n        const isActive = model.id === activeId;\n        return (\n          <div\n            key={model.id}\n            id={optionIdOf(baseId, model.id)}\n            role='option'\n            aria-selected={isActive}\n            onPointerMove={() => onActivate(model.id)}\n            onMouseDown={(event) => event.preventDefault()}\n            onClick={() => onPick(model.id)}\n            className='relative flex cursor-default items-start gap-2.5 rounded-md px-2 py-2'\n          >\n            {isActive && (\n              <motion.span\n                layoutId={highlightId}\n                layoutDependency={activeId}\n                transition={travel}\n                aria-hidden='true'\n                className='bg-foreground/5 absolute inset-0 rounded-md'\n              />\n            )}\n            <span className='relative flex min-w-0 flex-1 flex-col gap-1'>\n              <span className='flex items-baseline gap-2'>\n                <span className='shrink-0 text-[13px] font-medium'>\n                  <Marked text={model.name} query={query} />\n                </span>\n                <span className='text-muted-foreground min-w-0 truncate text-xs'>\n                  {model.hint}\n                </span>\n              </span>\n              <ModelFacts model={model} />\n              <CapabilityChips model={model} />\n            </span>\n            <AnimatePresence initial={false}>\n              {isPicked && (\n                <DrawnCheck\n                  key='mark'\n                  label='Current model'\n                  className='relative mt-0.5'\n                />\n              )}\n            </AnimatePresence>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n\ntype PickerTriggerProps = React.ComponentProps<typeof Button> & {\n  model: ModelOption;\n};\n\nfunction PickerTrigger({ model, ...props }: PickerTriggerProps) {\n  return (\n    <Button\n      type='button'\n      variant='outline'\n      aria-label={`Model: ${model.name}, change`}\n      className='gap-2 ps-2.5 pe-2'\n      {...props}\n    >\n      <LabTile lab={model.lab} />\n      <WordRoll text={model.name} />\n      <ChevronsUpDownIcon className='text-muted-foreground size-3.5' />\n    </Button>\n  );\n}\n\nexport type ModelPickerProps = {\n  models?: ModelOption[];\n  value: string;\n  onValueChange: (modelId: string) => void;\n  /** Left out, the picker is a dialog under 640px and a popover above. */\n  as?: PickerSurface;\n  /** Runs what the keys of the panel do while it is shown, for a demonstration or a control beside it. */\n  handleRef?: React.Ref<ModelPickerHandle>;\n  /** A demonstration drives the panel: its result counts are not read aloud. */\n  isDemonstrated?: boolean;\n};\n\nexport function ModelPicker({\n  models = MODELS,\n  value,\n  onValueChange,\n  as,\n  handleRef,\n  isDemonstrated = false,\n}: ModelPickerProps) {\n  const [isOpen, setIsOpen] = useState(false);\n  const [isInlineOpen, setIsInlineOpen] = useState(true);\n  const searchRef = useRef<HTMLInputElement>(null);\n  const panelId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const inlinePresence = rowPresenceOf(shouldReduceMotion);\n  const isWide = useSyncExternalStore(\n    subscribeToWidth,\n    isWideNow,\n    isWideOnServer\n  );\n  const surface = surfaceOf(as, isWide);\n  const picked = modelOf(value);\n\n  function pick(modelId: string) {\n    onValueChange(modelId);\n    setIsOpen(false);\n  }\n\n  const panel = (\n    <ModelPanel\n      models={models}\n      pickedId={value}\n      onPick={pick}\n      layout={surface}\n      searchRef={searchRef}\n      handleRef={handleRef}\n      isDemonstrated={isDemonstrated}\n    />\n  );\n\n  if (surface === 'inline') {\n    return (\n      <div className='flex flex-col gap-2'>\n        <div>\n          <PickerTrigger\n            model={picked}\n            aria-expanded={isInlineOpen}\n            aria-controls={panelId}\n            onClick={() => setIsInlineOpen((current) => !current)}\n          />\n        </div>\n        <AnimatePresence initial={false}>\n          {isInlineOpen && (\n            <motion.div\n              key='panel'\n              id={panelId}\n              role='group'\n              aria-label='Choose a model'\n              className='overflow-hidden'\n              {...inlinePresence}\n            >\n              <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] rounded-lg'>\n                {panel}\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    );\n  }\n\n  if (surface === 'dialog') {\n    return (\n      <Dialog open={isOpen} onOpenChange={setIsOpen}>\n        <DialogTrigger render={<PickerTrigger model={picked} />} />\n        <DialogContent\n          initialFocus={searchRef}\n          className='max-w-md p-0'\n          contentClassName='gap-0'\n          animateSize={false}\n        >\n          <DialogTitle className='sr-only'>Choose a model</DialogTitle>\n          {panel}\n        </DialogContent>\n      </Dialog>\n    );\n  }\n\n  return (\n    <Popover open={isOpen} onOpenChange={setIsOpen}>\n      <PopoverTrigger render={<PickerTrigger model={picked} />} />\n      <PopoverContent\n        initialFocus={searchRef}\n        align='start'\n        className='w-auto p-0'\n      >\n        <PopoverTitle className='sr-only'>Choose a model</PopoverTitle>\n        {panel}\n      </PopoverContent>\n    </Popover>\n  );\n}\n\ntype SurfaceChoice = 'auto' | PickerSurface;\n\nconst SURFACES: Segment<SurfaceChoice>[] = [\n  { value: 'inline', label: 'Inline' },\n  { value: 'auto', label: 'Auto' },\n  { value: 'popover', label: 'Popover' },\n  { value: 'dialog', label: 'Dialog' },\n];\n\nconst START_MODEL = 'claude-sonnet';\n\nconst DEMO_SEARCH = 'gem';\n\nfunction asOf(choice: SurfaceChoice) {\n  if (choice === 'auto') {\n    return undefined;\n  }\n  return choice;\n}\n\nfunction summaryOf(model: ModelOption) {\n  const lab = labOf(model.lab);\n  const context = contextLabelOf(model.contextTokens);\n  return `By ${lab.name}, ${context} context`;\n}\n\nexport default function Prompt03() {\n  const [modelId, setModelId] = useState(START_MODEL);\n  const [surface, setSurface] = useState<SurfaceChoice>('inline');\n  const picker = useRef<ModelPickerHandle>(null);\n  const model = modelOf(modelId);\n  const summary = summaryOf(model);\n\n  function resetDemo() {\n    setModelId(START_MODEL);\n    picker.current?.compare(false);\n    picker.current?.search('');\n    picker.current?.highlight(START_MODEL);\n  }\n\n  const searchTyping = prefixesOf(DEMO_SEARCH).map((typed, index) => ({\n    after: keyDelayOf(index, 900, 110),\n    run: () => picker.current?.search(typed),\n  }));\n  const steps: AutoplayStep[] = [\n    { after: 1400, run: () => picker.current?.move(1) },\n    { after: 520, run: () => picker.current?.move(1) },\n    { after: 520, run: () => picker.current?.move(1) },\n    ...searchTyping,\n    { after: 900, run: () => picker.current?.pickHighlighted() },\n    { after: 1300, run: () => picker.current?.search('') },\n    { after: 800, run: () => picker.current?.compare(true) },\n    { after: 2200, run: () => picker.current?.compare(false) },\n    { after: 600, run: hold },\n  ];\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 2400,\n    onReset: resetDemo,\n  });\n\n  useKeptHeight(ref);\n\n  return (\n    <div ref={ref} className='flex w-full max-w-[24rem] flex-col gap-3'>\n      <div className='bg-card hairline-ring ring-border flex flex-col gap-3 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <div className='flex flex-col gap-1.5'>\n          <p className='text-muted-foreground text-xs'>Answers come from</p>\n          <div>\n            <ModelPicker\n              value={modelId}\n              onValueChange={setModelId}\n              as={asOf(surface)}\n              handleRef={picker}\n              isDemonstrated={isAutoplaying}\n            />\n          </div>\n        </div>\n        <p className='text-muted-foreground text-xs'>\n          <WordRoll text={summary} />\n        </p>\n      </div>\n      <div className='flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5 px-1'>\n        <p className='text-muted-foreground text-xs'>Opens as</p>\n        <Segments\n          value={surface}\n          segments={SURFACES}\n          onValueChange={setSurface}\n          label='Opens as'\n          className='w-64 max-w-full'\n          itemClassName='px-1.5'\n        />\n      </div>\n      <LiveRegion\n        message={spokenUnless(isAutoplaying, `${model.name} picked`)}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/prompt/prompt-03.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/lab-tile.tsx",
      "content": "import { BrandTile, type BrandTileSize } from '@/registry/ndeko/ui/brand-tile';\n\nimport { labOf, type LabId } from './labs';\n\ntype LabTileProps = {\n  lab: LabId;\n  size?: BrandTileSize;\n  className?: string;\n};\n\nexport function LabTile({ lab, size = 'md', className }: LabTileProps) {\n  const entry = labOf(lab);\n\n  return <BrandTile brand={entry.brand} size={size} className={className} />;\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/lab-tile.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/labs.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport type LabId = 'anthropic' | 'openai' | 'google' | 'deepseek';\n\nexport type Lab = {\n  id: LabId;\n  name: string;\n  brand: BrandSlug;\n};\n\nexport type Capability = 'vision' | 'tools' | 'reasoning' | 'long-context';\n\nexport type Tier = 1 | 2 | 3;\n\nexport type ModelOption = {\n  id: string;\n  name: string;\n  lab: LabId;\n  /** How many tokens the model reads at once. Illustrative in the demos. */\n  contextTokens: number;\n  /** 1 is the slowest, 3 the fastest. */\n  speed: Tier;\n  /** 1 is the cheapest, 3 the dearest. */\n  price: Tier;\n  capabilities: Capability[];\n  hint: string;\n};\n\nexport const LABS: Lab[] = [\n  { id: 'anthropic', name: 'Anthropic', brand: 'claude' },\n  { id: 'openai', name: 'OpenAI', brand: 'openai' },\n  { id: 'google', name: 'Google', brand: 'gemini' },\n  { id: 'deepseek', name: 'DeepSeek', brand: 'deepseek' },\n];\n\n/** Families without a version number; context, speed and price are coarse tiers for the demos, not facts about a model. */\nexport const MODELS: ModelOption[] = [\n  {\n    id: 'claude-haiku',\n    name: 'Claude Haiku',\n    lab: 'anthropic',\n    contextTokens: 200_000,\n    speed: 3,\n    price: 1,\n    capabilities: ['tools'],\n    hint: 'Quick replies and small edits',\n  },\n  {\n    id: 'claude-sonnet',\n    name: 'Claude Sonnet',\n    lab: 'anthropic',\n    contextTokens: 200_000,\n    speed: 2,\n    price: 2,\n    capabilities: ['vision', 'tools', 'long-context'],\n    hint: 'Everyday work across long files',\n  },\n  {\n    id: 'claude-opus',\n    name: 'Claude Opus',\n    lab: 'anthropic',\n    contextTokens: 200_000,\n    speed: 1,\n    price: 3,\n    capabilities: ['vision', 'tools', 'reasoning', 'long-context'],\n    hint: 'Hard problems that need a plan',\n  },\n  {\n    id: 'gpt-mini',\n    name: 'GPT mini',\n    lab: 'openai',\n    contextTokens: 128_000,\n    speed: 3,\n    price: 1,\n    capabilities: ['tools'],\n    hint: 'Cheap bulk tasks',\n  },\n  {\n    id: 'gemini-pro',\n    name: 'Gemini Pro',\n    lab: 'google',\n    contextTokens: 1_000_000,\n    speed: 1,\n    price: 3,\n    capabilities: ['vision', 'tools', 'reasoning', 'long-context'],\n    hint: 'Whole repositories at once',\n  },\n  {\n    id: 'deepseek',\n    name: 'DeepSeek',\n    lab: 'deepseek',\n    contextTokens: 64_000,\n    speed: 2,\n    price: 1,\n    capabilities: ['tools', 'reasoning'],\n    hint: 'Reasoning on a budget',\n  },\n];\n\nexport const CAPABILITIES: Capability[] = [\n  'vision',\n  'tools',\n  'reasoning',\n  'long-context',\n];\n\nexport const CAPABILITY_LABEL: Record<Capability, string> = {\n  vision: 'Vision',\n  tools: 'Tools',\n  reasoning: 'Reasoning',\n  'long-context': 'Long context',\n};\n\nexport const SPEED_WORD: Record<Tier, string> = {\n  1: 'Slow',\n  2: 'Medium speed',\n  3: 'Fast',\n};\n\nexport const PRICE_WORD: Record<Tier, string> = {\n  1: 'Low price',\n  2: 'Medium price',\n  3: 'High price',\n};\n\nconst FALLBACK_LAB = LABS[0];\n\nconst FALLBACK_MODEL = MODELS[0];\n\nexport function labOf(id: LabId) {\n  const lab = LABS.find((candidate) => candidate.id === id);\n  return lab ?? FALLBACK_LAB;\n}\n\nexport function modelOf(id: string) {\n  const model = MODELS.find((candidate) => candidate.id === id);\n  return model ?? FALLBACK_MODEL;\n}\n\n/** 32k, 200k, 1M. */\nexport function contextLabelOf(tokens: number) {\n  const isMillion = tokens >= 1_000_000;\n  if (isMillion) {\n    const millions = Math.round(tokens / 1_000_000);\n    return `${millions}M`;\n  }\n  const thousands = Math.round(tokens / 1000);\n  return `${thousands}k`;\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/labs.ts"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/marked.tsx",
      "content": "type TextPiece = { text: string; isMatch: boolean };\n\nexport function piecesOf(text: string, query: string): TextPiece[] {\n  const needle = query.trim().toLowerCase();\n  if (needle === '') {\n    return [{ text, isMatch: false }];\n  }\n  const haystack = text.toLowerCase();\n  const pieces: TextPiece[] = [];\n  let cursor = 0;\n  let found = haystack.indexOf(needle, cursor);\n  while (found >= 0) {\n    const before = text.slice(cursor, found);\n    const matchEnd = found + needle.length;\n    const match = text.slice(found, matchEnd);\n    if (before !== '') {\n      pieces.push({ text: before, isMatch: false });\n    }\n    pieces.push({ text: match, isMatch: true });\n    cursor = matchEnd;\n    found = haystack.indexOf(needle, cursor);\n  }\n  const rest = text.slice(cursor);\n  if (rest !== '') {\n    pieces.push({ text: rest, isMatch: false });\n  }\n  return pieces;\n}\n\nexport function includesQuery(text: string, query: string) {\n  const needle = query.trim().toLowerCase();\n  if (needle === '') {\n    return true;\n  }\n  const haystack = text.toLowerCase();\n  return haystack.includes(needle);\n}\n\ntype MarkedProps = {\n  text: string;\n  query: string;\n};\n\nexport function Marked({ text, query }: MarkedProps) {\n  const pieces = piecesOf(text, query);\n\n  return (\n    <>\n      {pieces.map((piece, index) => {\n        if (piece.isMatch) {\n          return (\n            <mark\n              key={index}\n              className='bg-warning/25 text-foreground rounded-[3px] px-px'\n            >\n              {piece.text}\n            </mark>\n          );\n        }\n        return <span key={index}>{piece.text}</span>;\n      })}\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/marked.tsx"
    }
  ],
  "categories": [
    "components",
    "prompt"
  ],
  "type": "registry:component"
}