{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "follow-up-suggestions",
  "title": "Follow-up Suggestions",
  "description": "A keyboard-driven next step picker with numbered options and a free text custom question.",
  "dependencies": [
    "cn@^0.3.0"
  ],
  "registryDependencies": [
    "button",
    "card",
    "https://pastaui.com/r/pastaui-styles.json",
    "kbd",
    "toggle-group"
  ],
  "files": [
    {
      "path": "src/components/ai/follow-up-suggestions.tsx",
      "content": "import * as React from 'react'\nimport { useId, useRef, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'\nimport { Kbd } from '@/components/ui/kbd'\nimport { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'\nimport { cn } from 'cn'\n\ninterface FollowUpSuggestion {\n  custom?: boolean\n  id: string\n  label: string\n  placeholder?: string\n}\n\ninterface FollowUpSuggestionsProps extends Omit<React.ComponentProps<'section'>, 'onSelect'> {\n  defaultSelectedId?: string\n  items: FollowUpSuggestion[]\n  onDismiss?: () => void\n  onSelect?: (id: string, value?: string) => void\n  onSelectedIdChange?: (id: string) => void\n  selectedId?: string\n  title?: string\n}\n\nfunction FollowUpSuggestions({\n  className,\n  defaultSelectedId,\n  items,\n  onDismiss,\n  onSelect,\n  onSelectedIdChange,\n  selectedId,\n  title = 'What would you like to do?',\n  ...props\n}: FollowUpSuggestionsProps) {\n  const titleId = useId()\n  const itemElements = useRef(new Map<string, HTMLButtonElement>())\n  const [uncontrolledSelectedId, setUncontrolledSelectedId] = useState(\n    defaultSelectedId ?? items[0]?.id,\n  )\n  const currentSelectedId = selectedId ?? uncontrolledSelectedId\n  const currentItem = items.find((item) => item.id === currentSelectedId)\n  const [customValue, setCustomValue] = useState('')\n  const customRef = useRef<HTMLInputElement>(null)\n\n  function selectSuggestion(id: string, focus = false) {\n    if (selectedId === undefined) setUncontrolledSelectedId(id)\n    onSelectedIdChange?.(id)\n    if (focus) itemElements.current.get(id)?.focus()\n  }\n\n  function moveSelection(direction: -1 | 1) {\n    const currentIndex = Math.max(\n      0,\n      items.findIndex((item) => item.id === currentSelectedId),\n    )\n    const nextIndex = (currentIndex + direction + items.length) % items.length\n    const nextItem = items[nextIndex]\n\n    if (nextItem) selectSuggestion(nextItem.id, true)\n  }\n\n  function submitSelection() {\n    if (!currentSelectedId) return\n    if (currentItem?.custom) {\n      if (!customValue.trim()) return customRef.current?.focus()\n      onSelect?.(currentSelectedId, customValue.trim())\n      return\n    }\n    onSelect?.(currentSelectedId)\n  }\n\n  function handleKeyDown(event: React.KeyboardEvent<HTMLElement>) {\n    if (event.key === 'ArrowDown') {\n      event.preventDefault()\n      moveSelection(1)\n      return\n    }\n\n    if (event.key === 'ArrowUp') {\n      event.preventDefault()\n      moveSelection(-1)\n      return\n    }\n\n    if (event.key === 'Enter') {\n      event.preventDefault()\n      submitSelection()\n      return\n    }\n\n    if (event.key === 'Escape') {\n      event.preventDefault()\n      onDismiss?.()\n      return\n    }\n\n    const shortcutIndex = Number(event.key) - 1\n    const shortcutItem = items[shortcutIndex]\n    if (shortcutItem && shortcutIndex >= 0 && shortcutIndex <= 8) {\n      event.preventDefault()\n      selectSuggestion(shortcutItem.id, true)\n    }\n  }\n\n  return (\n    <section\n      aria-labelledby={titleId}\n      className={cn('w-full tracking-[-0.05px]', className)}\n      data-slot=\"follow-up-suggestions\"\n      {...props}\n    >\n      <Card className=\"gap-2 rounded-[16px] pt-5 shadow-linear-surface ring-foreground/8\" size=\"sm\">\n        <CardHeader className=\"mb-2\">\n          <CardTitle\n            className=\"pl-3 card-heading leading-[19.25px] text-muted-foreground group-data-[size=sm]/card:text-[15px]\"\n            id={titleId}\n          >\n            {title}\n          </CardTitle>\n        </CardHeader>\n\n        <CardContent className=\"text-sm leading-5 font-[450]\">\n          <ToggleGroup\n            aria-label={title}\n            className=\"flex w-full flex-col items-stretch gap-1 bg-transparent p-0\"\n            onKeyDown={handleKeyDown}\n            onValueChange={(value) => {\n              const nextSelectedId = value[0]\n              if (nextSelectedId) selectSuggestion(nextSelectedId)\n            }}\n            orientation=\"vertical\"\n            value={currentSelectedId ? [currentSelectedId] : []}\n          >\n            {items.map((item, index) => {\n              const isSelected = item.id === currentSelectedId\n\n              return (\n                <ToggleGroupItem\n                  key={item.id}\n                  ref={(element) => {\n                    if (element) itemElements.current.set(item.id, element)\n                    else itemElements.current.delete(item.id)\n                  }}\n                  className=\"group/suggestion h-auto min-h-10 w-full justify-start gap-3 rounded-[10px] px-3 py-2 text-left text-sm leading-5 font-[450] text-muted-foreground hover:bg-muted/70 hover:text-muted-foreground data-pressed:bg-muted data-pressed:text-muted-foreground data-pressed:shadow-none\"\n                  value={item.id}\n                >\n                  {isSelected ? (\n                    <span className=\"flex size-6 shrink-0 items-center justify-center text-[13px] text-muted-foreground\">\n                      {index + 1}\n                    </span>\n                  ) : (\n                    <Kbd className=\"size-6 shrink-0 px-0 text-xs font-[450] shadow-none\">\n                      {index + 1}\n                    </Kbd>\n                  )}\n                  <span className=\"truncate\">{item.label}</span>\n                </ToggleGroupItem>\n              )\n            })}\n          </ToggleGroup>\n          <div\n            className={cn(\n              'grid transition-[grid-template-rows,opacity] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)]',\n              currentItem?.custom\n                ? 'mt-1 grid-rows-[1fr] opacity-100'\n                : 'grid-rows-[0fr] opacity-0',\n            )}\n          >\n            <div className=\"overflow-hidden\">\n              <label className=\"sr-only\" htmlFor={`${titleId}-custom`}>\n                {currentItem?.label ?? 'Your question'}\n              </label>\n              <input\n                className=\"h-10 w-full rounded-[10px] bg-muted/70 px-3 text-sm leading-5 font-[450] text-muted-foreground outline-none placeholder:text-muted-foreground/60\"\n                id={`${titleId}-custom`}\n                onChange={(event) => setCustomValue(event.target.value)}\n                onKeyDown={(event) => {\n                  if (event.key === 'Enter') {\n                    event.preventDefault()\n                    submitSelection()\n                  }\n                  if (event.key === 'Escape') onDismiss?.()\n                }}\n                placeholder={currentItem?.placeholder ?? 'Type your question'}\n                ref={customRef}\n                tabIndex={currentItem?.custom ? 0 : -1}\n                value={customValue}\n              />\n            </div>\n          </div>\n        </CardContent>\n\n        <CardFooter className=\"flex flex-wrap justify-between gap-3 border-t-0 bg-transparent pt-1 pb-5\">\n          <div className=\"ml-auto flex items-center gap-1.5\">\n            {onDismiss && (\n              <Button\n                className=\"h-7 rounded-full px-3 text-muted-foreground hover:text-muted-foreground\"\n                onClick={onDismiss}\n                size=\"sm\"\n                variant=\"ghost\"\n              >\n                Dismiss\n                <Kbd className=\"ml-1 shadow-none\">Esc</Kbd>\n              </Button>\n            )}\n            <Button\n              className=\"h-7 rounded-full border-0 bg-primary bg-linear-to-b from-[color-mix(in_oklch,var(--primary),var(--primary-foreground)_30%)] to-primary px-3 text-primary-foreground shadow-[inset_0_1px_0_rgba(255,255,255,0.14),0_1px_2px_rgba(0,0,0,0.18)] shadow-none hover:brightness-110 dark:bg-none\"\n              disabled={!currentSelectedId || (currentItem?.custom && !customValue.trim())}\n              onClick={submitSelection}\n              size=\"sm\"\n              variant=\"default\"\n            >\n              Submit\n              <Kbd className=\"ml-0.5 size-4 min-h-4 min-w-4 bg-primary-foreground/10 p-0 leading-none text-primary-foreground shadow-none\">\n                <svg aria-hidden=\"true\" className=\"size-3\" viewBox=\"0 0 24 24\" fill=\"none\">\n                  <path\n                    d=\"M20 5v10H4m5-5-5 5 5 5\"\n                    stroke=\"currentColor\"\n                    strokeWidth=\"1.5\"\n                    strokeLinecap=\"round\"\n                    strokeLinejoin=\"round\"\n                  />\n                </svg>\n                <span className=\"sr-only\">Enter</span>\n              </Kbd>\n            </Button>\n          </div>\n        </CardFooter>\n      </Card>\n    </section>\n  )\n}\n\nexport { FollowUpSuggestions }\nexport type { FollowUpSuggestion, FollowUpSuggestionsProps }\n",
      "type": "registry:component",
      "target": "@components/ai/follow-up-suggestions.tsx"
    }
  ],
  "type": "registry:component"
}