{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "review-13",
  "title": "Staged action",
  "description": "What the agent is about to run as fields you can correct, where a changed field marks itself as edited with Reset, and Approve becomes the result while Discard folds away with Undo.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.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/mesh-tile.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.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/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/review/review-13.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useEffect, useImperativeHandle, useId, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll, type WordRollWord } from '@/components/core/word-roll';\nimport {\n  typingSteps,\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 { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { seriesColorOf, type RunAgent } from '@/registry/ndeko/lib/agent-run';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  pressedQuietOf,\n  pressedSolidOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  LinkIcon,\n  PencilIcon,\n  RotateCcwIcon,\n  TriangleAlertIcon,\n  UndoIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { fadePresence, springOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\n\nimport { SettledLine } from './_parts/settled-line';\nimport { useFocusHandOff } from './_parts/use-focus-hand-off';\n\nexport type StagedField = {\n  id: string;\n  label: string;\n  /** What the agent filled in. */\n  value: string;\n  /** Where the agent found the value. It shows while the field is being edited. */\n  source: string;\n  kind?: 'text' | 'amount';\n  /** A unit shown after the value, such as a currency. */\n  suffix?: string;\n  isOptional?: boolean;\n  /** The field takes the whole row. */\n  isWide?: boolean;\n};\n\nexport type StagedValues = Record<string, string>;\n\ntype StagedPhase = 'editing' | 'approving' | 'confirmed' | 'done' | 'discarded';\n\n/** The control a demonstration holds down. */\nexport type StagedActionPress = 'approve' | 'discard' | 'undo' | 'restage';\n\nexport type StagedActionHandle = {\n  approve: () => void;\n  discard: () => void;\n  undo: () => void;\n  restage: () => void;\n};\n\nconst RUNNING_MS = 700;\n\nconst CONFIRMED_MS = 500;\n\nconst APPROVE_LABELS: Record<MorphState, string> = {\n  idle: 'Approve',\n  busy: 'Running',\n  done: 'Done',\n};\n\nconst DISCARDED_TEXT = 'Discarded, nothing ran';\n\nfunction valueOf(field: StagedField, values: StagedValues) {\n  return values[field.id] ?? field.value;\n}\n\nfunction isEditedField(field: StagedField, values: StagedValues) {\n  return valueOf(field, values) !== field.value;\n}\n\nfunction errorOf(field: StagedField, value: string) {\n  const trimmed = value.trim();\n  if (trimmed === '') {\n    if (field.isOptional) {\n      return '';\n    }\n    return `${field.label} is required`;\n  }\n  if (field.kind === 'amount') {\n    const amount = Number(trimmed);\n    const isValid = Number.isFinite(amount) && amount > 0;\n    if (!isValid) {\n      return 'Enter an amount above 0';\n    }\n  }\n  return '';\n}\n\nfunction viewOf(phase: StagedPhase) {\n  if (phase === 'done') {\n    return 'done';\n  }\n  if (phase === 'discarded') {\n    return 'discarded';\n  }\n  return 'form';\n}\n\nfunction approveStateOf(phase: StagedPhase): MorphState {\n  if (phase === 'approving') {\n    return 'busy';\n  }\n  if (phase === 'confirmed') {\n    return 'done';\n  }\n  return 'idle';\n}\n\nfunction editedWordsOf(count: number): WordRollWord[] {\n  if (count === 0) {\n    return ['None', 'edited'];\n  }\n  const countWord = {\n    key: 'count',\n    text: String(count),\n    node: <MotionNumber value={count} />,\n  };\n  return [countWord, 'edited'];\n}\n\nfunction editedRingOf(isEdited: boolean) {\n  if (isEdited) {\n    return 'ring-primary/45';\n  }\n  return undefined;\n}\n\nfunction describedByOf(\n  isShown: boolean,\n  showsError: boolean,\n  sourceId: string,\n  errorId: string\n) {\n  const ids: string[] = [];\n  if (isShown) {\n    ids.push(sourceId);\n  }\n  if (showsError) {\n    ids.push(errorId);\n  }\n  return ids.join(' ');\n}\n\nfunction handOffOf(isFirst: boolean) {\n  if (isFirst) {\n    return '';\n  }\n  return undefined;\n}\n\nfunction wideClassOf(isWide: boolean | undefined) {\n  if (isWide) {\n    return '@sm:col-span-2';\n  }\n  return undefined;\n}\n\ntype FieldRowProps = {\n  field: StagedField;\n  value: string;\n  agentName: string;\n  isFirst: boolean;\n  isShown: boolean;\n  isLocked: boolean;\n  onValueChange: (fieldId: string, value: string) => void;\n  onActivate: (fieldId: string) => void;\n  onDeactivate: (fieldId: string) => void;\n};\n\nfunction FieldRow({\n  field,\n  value,\n  agentName,\n  isFirst,\n  isShown,\n  isLocked,\n  onValueChange,\n  onActivate,\n  onDeactivate,\n}: FieldRowProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const pop = springOf(shouldReduceMotion);\n  const inputId = useId();\n  const sourceId = useId();\n  const errorId = useId();\n  const isEdited = value !== field.value;\n  const error = errorOf(field, value);\n  const showsError = error !== '' && !isShown;\n  const hasSuffix = field.suffix !== undefined;\n  const describedBy = describedByOf(isShown, showsError, sourceId, errorId);\n\n  function changeValue(event: React.ChangeEvent<HTMLInputElement>) {\n    onValueChange(field.id, event.target.value);\n  }\n\n  function reset() {\n    onValueChange(field.id, field.value);\n  }\n\n  function resetFromKey(event: React.KeyboardEvent<HTMLInputElement>) {\n    const isEscape = event.key === 'Escape';\n    if (isEscape && isEdited) {\n      event.preventDefault();\n      reset();\n    }\n  }\n\n  return (\n    <div className={cn('flex min-w-0 flex-col', wideClassOf(field.isWide))}>\n      <div className='flex h-6 items-center justify-between gap-2 pb-1.5'>\n        <label htmlFor={inputId} className='text-xs font-medium'>\n          {field.label}\n        </label>\n        <span className='flex items-center gap-1'>\n          <AnimatePresence initial={false}>\n            {isEdited && (\n              <motion.span\n                key='edited'\n                initial={{ opacity: 0, scale: 0.85 }}\n                animate={{ opacity: 1, scale: 1 }}\n                exit={{ opacity: 0, scale: 0.85 }}\n                transition={pop}\n              >\n                <Chip color='var(--primary)'>\n                  <PencilIcon />\n                  Edited\n                </Chip>\n              </motion.span>\n            )}\n          </AnimatePresence>\n          <AnimatePresence initial={false}>\n            {isEdited && !isLocked && (\n              <motion.span\n                key='reset'\n                initial={{ opacity: 0 }}\n                animate={{ opacity: 1 }}\n                exit={{ opacity: 0 }}\n                transition={pop}\n              >\n                <Button\n                  type='button'\n                  variant='ghost'\n                  size='sm'\n                  onClick={reset}\n                  aria-label={`Reset ${field.label} to ${field.value}`}\n                  className='text-muted-foreground h-5 px-1.5'\n                >\n                  <RotateCcwIcon className='size-3' />\n                  Reset\n                </Button>\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </span>\n      </div>\n      <div className='relative'>\n        <Input\n          id={inputId}\n          value={value}\n          disabled={isLocked}\n          autoComplete='off'\n          aria-invalid={showsError}\n          aria-describedby={describedBy}\n          data-hand-off={handOffOf(isFirst)}\n          onChange={changeValue}\n          onFocus={() => onActivate(field.id)}\n          onBlur={() => onDeactivate(field.id)}\n          onKeyDown={resetFromKey}\n          className={cn(\n            'transition-[color,box-shadow,border-color,background-color]',\n            editedRingOf(isEdited),\n            hasSuffix && 'pe-12'\n          )}\n        />\n        {hasSuffix && (\n          <span\n            aria-hidden='true'\n            className='text-muted-foreground pointer-events-none absolute inset-y-0 end-2.5 flex items-center text-xs'\n          >\n            {field.suffix}\n          </span>\n        )}\n      </div>\n      <p\n        id={errorId}\n        className={cn(\n          'text-destructive-ink flex items-center gap-1 pt-1.5 text-xs',\n          !showsError && 'hidden'\n        )}\n      >\n        {error}\n      </p>\n      <Fold open={isShown} id={sourceId}>\n        <div className='text-muted-foreground flex flex-col gap-0.5 pt-1.5 text-xs leading-5'>\n          <p className='flex items-start gap-1.5'>\n            <LinkIcon className='mt-0.5 size-3.5 shrink-0' />\n            {field.source}\n          </p>\n          {isEdited && (\n            <p className='ps-5'>\n              {agentName} wrote{' '}\n              <span className='tabular-nums'>{field.value}</span>\n            </p>\n          )}\n        </div>\n      </Fold>\n    </div>\n  );\n}\n\nexport type StagedActionProps = {\n  agent: Pick<RunAgent, 'name' | 'series'>;\n  /** What will run once it is approved: \"Create a refund\". */\n  title: string;\n  fields: StagedField[];\n  values: StagedValues;\n  onValueChange: (fieldId: string, value: string) => void;\n  /** The line shown once it ran, built from the values that were approved. */\n  describeResult: (values: StagedValues) => string;\n  /** Shows the source of this field as if it had focus, for a demonstration that points at it. */\n  pointedId?: string | null;\n  onApprove?: (values: StagedValues) => void;\n  onDiscard?: () => void;\n  onUndo?: () => void;\n  /** Putting the card back to its first state: change this number. */\n  resetToken?: number;\n  handleRef?: React.Ref<StagedActionHandle>;\n  pressed?: StagedActionPress | null;\n  /** A demonstration is not read aloud. */\n  isDemonstrating?: boolean;\n  className?: string;\n};\n\nexport function StagedAction({\n  agent,\n  title,\n  fields,\n  values,\n  onValueChange,\n  describeResult,\n  pointedId = null,\n  onApprove,\n  onDiscard,\n  onUndo,\n  resetToken = 0,\n  handleRef,\n  pressed = null,\n  isDemonstrating = false,\n  className,\n}: StagedActionProps) {\n  const [phase, setPhase] = useState<StagedPhase>('editing');\n  const [activeId, setActiveId] = useState<string | null>(null);\n  const [approvedValues, setApprovedValues] = useState<StagedValues>({});\n  const [notice, setNotice] = useState('');\n  const [seenToken, setSeenToken] = useState(resetToken);\n  const { schedule, clearAll } = useTimeouts();\n  const fade = fadePresence();\n  const view = viewOf(phase);\n  const { rootRef, markIfFocusInside } = useFocusHandOff(view);\n  const shownId = activeId ?? pointedId;\n  const isLocked = phase === 'approving' || phase === 'confirmed';\n  const editedCount = fields.filter((field) =>\n    isEditedField(field, values)\n  ).length;\n  const editedWords = editedWordsOf(editedCount);\n  const hasErrors = fields.some((field) => {\n    const value = valueOf(field, values);\n    return errorOf(field, value) !== '';\n  });\n\n  useEffect(() => {\n    clearAll();\n  }, [resetToken, clearAll]);\n\n  if (seenToken !== resetToken) {\n    setSeenToken(resetToken);\n    setPhase('editing');\n    setActiveId(null);\n  }\n\n  function finishApproval(approved: StagedValues) {\n    markIfFocusInside();\n    setPhase('done');\n    setNotice(describeResult(approved));\n    onApprove?.(approved);\n  }\n\n  function approve() {\n    const isEditing = phase === 'editing';\n    if (!isEditing) {\n      return;\n    }\n    if (hasErrors) {\n      setNotice('Fix the fields marked as missing first');\n      return;\n    }\n    const approved = { ...values };\n    setApprovedValues(approved);\n    setActiveId(null);\n    setPhase('approving');\n    schedule(() => setPhase('confirmed'), RUNNING_MS);\n    schedule(() => finishApproval(approved), RUNNING_MS + CONFIRMED_MS);\n  }\n\n  function discard() {\n    const isEditing = phase === 'editing';\n    if (!isEditing) {\n      return;\n    }\n    markIfFocusInside();\n    setActiveId(null);\n    setPhase('discarded');\n    setNotice(DISCARDED_TEXT);\n    onDiscard?.();\n  }\n\n  function undo() {\n    markIfFocusInside();\n    setPhase('editing');\n    setNotice('The action is staged again');\n    onUndo?.();\n  }\n\n  function restage() {\n    markIfFocusInside();\n    for (const field of fields) {\n      onValueChange(field.id, field.value);\n    }\n    setPhase('editing');\n    setNotice('The action is staged again');\n  }\n\n  useImperativeHandle(handleRef, () => ({ approve, discard, undo, restage }));\n\n  function activate(fieldId: string) {\n    setActiveId(fieldId);\n  }\n\n  function deactivate(fieldId: string) {\n    setActiveId((current) => {\n      if (current === fieldId) {\n        return null;\n      }\n      return current;\n    });\n    const field = fields.find((entry) => entry.id === fieldId);\n    if (!field) {\n      return;\n    }\n    const error = errorOf(field, valueOf(field, values));\n    if (error !== '') {\n      setNotice(error);\n    }\n  }\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\n        'surface-raised @container overflow-hidden rounded-xl',\n        className\n      )}\n    >\n      <AnimatedSize>\n        <AnimatePresence initial={false} mode='popLayout'>\n          <motion.div key={view} {...fade}>\n            {view === 'done' && (\n              <SettledLine\n                icon={<DrawnCheck tone='success' entrance='draw' />}\n                actionLabel='Stage again'\n                actionIcon={<RotateCcwIcon />}\n                onAction={restage}\n                isActionPressed={pressed === 'restage'}\n              >\n                <span className='font-medium'>\n                  {describeResult(approvedValues)}\n                </span>\n              </SettledLine>\n            )}\n            {view === 'discarded' && (\n              <SettledLine\n                icon={<XIcon className='text-muted-foreground size-4' />}\n                actionLabel='Undo'\n                actionIcon={<UndoIcon />}\n                onAction={undo}\n                isActionPressed={pressed === 'undo'}\n              >\n                <span className='text-muted-foreground'>{DISCARDED_TEXT}</span>\n              </SettledLine>\n            )}\n            {view === 'form' && (\n              <div className='flex flex-col gap-3.5 p-4'>\n                <div className='flex items-center justify-between gap-3'>\n                  <span className='text-muted-foreground flex min-w-0 items-center gap-2 text-xs'>\n                    <MeshTile\n                      seed={agent.name}\n                      color={seriesColorOf(agent.series)}\n                    />\n                    <span className='min-w-0 truncate'>\n                      <span className='text-foreground font-medium'>\n                        {agent.name}\n                      </span>{' '}\n                      staged this from the conversation\n                    </span>\n                  </span>\n                  <span className='text-muted-foreground shrink-0 text-xs'>\n                    <WordRoll words={editedWords} />\n                  </span>\n                </div>\n                <p className='text-sm font-medium text-balance'>{title}</p>\n                <div className='grid grid-cols-1 gap-x-3 gap-y-3 @sm:grid-cols-2'>\n                  {fields.map((field, index) => (\n                    <FieldRow\n                      key={field.id}\n                      field={field}\n                      value={valueOf(field, values)}\n                      agentName={agent.name}\n                      isFirst={index === 0}\n                      isShown={shownId === field.id}\n                      isLocked={isLocked}\n                      onValueChange={onValueChange}\n                      onActivate={activate}\n                      onDeactivate={deactivate}\n                    />\n                  ))}\n                </div>\n                <div className='flex flex-wrap items-center gap-2'>\n                  <MorphButton\n                    type='button'\n                    size='sm'\n                    state={approveStateOf(phase)}\n                    labels={APPROVE_LABELS}\n                    disabled={hasErrors}\n                    onClick={approve}\n                    className={pressedSolidOf(pressed === 'approve')}\n                  />\n                  <Button\n                    type='button'\n                    size='sm'\n                    variant='outline'\n                    disabled={isLocked}\n                    onClick={discard}\n                    className={pressedQuietOf(pressed === 'discard')}\n                  >\n                    Discard\n                  </Button>\n                  {hasErrors && (\n                    <p className='text-warning-foreground flex items-center gap-1.5 text-xs'>\n                      <TriangleAlertIcon className='size-3.5' />\n                      Fill the empty fields to approve\n                    </p>\n                  )}\n                  {!hasErrors && (\n                    <p className='text-muted-foreground hidden text-xs @md:block'>\n                      Nothing runs until you approve\n                    </p>\n                  )}\n                </div>\n              </div>\n            )}\n          </motion.div>\n        </AnimatePresence>\n      </AnimatedSize>\n      <LiveRegion message={spokenUnless(isDemonstrating, notice)} />\n    </div>\n  );\n}\n\nconst PLANNER: Pick<RunAgent, 'name' | 'series'> = {\n  name: 'Planner',\n  series: 1,\n};\n\nconst FIELDS: StagedField[] = [\n  {\n    id: 'order',\n    label: 'Order',\n    value: 'ORD-48217',\n    source: 'Your message at 14:02 names this order',\n  },\n  {\n    id: 'customer',\n    label: 'Customer',\n    value: 'Grace Mbuyi',\n    source: 'The customer on order ORD-48217',\n  },\n  {\n    id: 'amount',\n    label: 'Amount',\n    value: '48.00',\n    suffix: 'EUR',\n    kind: 'amount',\n    source: 'Price of the cracked item, line 2 of the order',\n  },\n  {\n    id: 'reason',\n    label: 'Reason',\n    value: 'Item arrived damaged',\n    source: 'Customer email of 12 November',\n  },\n];\n\nconst ORIGINAL_VALUES: StagedValues = {\n  order: 'ORD-48217',\n  customer: 'Grace Mbuyi',\n  amount: '48.00',\n  reason: 'Item arrived damaged',\n};\n\nconst EDITED_AMOUNT = '36.00';\n\nconst RESTING_VALUES: StagedValues = {\n  ...ORIGINAL_VALUES,\n  amount: EDITED_AMOUNT,\n};\n\nfunction describeRefund(values: StagedValues) {\n  return `Refund created: ${values.amount} EUR to ${values.customer}`;\n}\n\nfunction initialValuesOf(isResting: boolean) {\n  if (isResting) {\n    return RESTING_VALUES;\n  }\n  return ORIGINAL_VALUES;\n}\n\nfunction initialPointedOf(isResting: boolean) {\n  if (isResting) {\n    return 'amount';\n  }\n  return null;\n}\n\ntype StagedDemoProps = {\n  isResting: boolean;\n};\n\nfunction StagedDemo({ isResting }: StagedDemoProps) {\n  const [values, setValues] = useState(initialValuesOf(isResting));\n  const [pointedId, setPointedId] = useState<string | null>(\n    initialPointedOf(isResting)\n  );\n  const [round, setRound] = useState(0);\n  const card = useRef<StagedActionHandle>(null);\n  const { pressed, press } = usePress<StagedActionPress>();\n\n  function changeValue(fieldId: string, value: string) {\n    setValues((current) => ({ ...current, [fieldId]: value }));\n  }\n\n  function typeAmount(typed: string) {\n    changeValue('amount', typed);\n  }\n\n  function resetDemo() {\n    setValues(ORIGINAL_VALUES);\n    setPointedId(null);\n    setRound((current) => current + 1);\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 1500, run: () => setPointedId('amount') },\n    ...typingSteps(EDITED_AMOUNT, typeAmount, {\n      startAfter: 1100,\n      characterMs: 130,\n    }),\n    { after: 1500, run: () => press('approve') },\n    { after: PRESS_LEAD_MS, run: () => setPointedId(null) },\n    { after: 0, run: () => card.current?.approve() },\n    { after: 3600, run: hold },\n  ];\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 2000,\n    onReset: resetDemo,\n  });\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[23rem] w-full max-w-[30rem] flex-col gap-2'\n    >\n      <StagedAction\n        agent={PLANNER}\n        title='Create a refund'\n        fields={FIELDS}\n        values={values}\n        onValueChange={changeValue}\n        describeResult={describeRefund}\n        pointedId={pointedId}\n        resetToken={round}\n        handleRef={card}\n        pressed={pressed}\n        isDemonstrating={isAutoplaying}\n      />\n      <p className='text-muted-foreground px-1 text-xs'>\n        Illustrative refund on sample data\n      </p>\n    </div>\n  );\n}\n\nexport default function Review13() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const restKey = String(shouldReduceMotion);\n\n  return <StagedDemo key={restKey} isResting={shouldReduceMotion} />;\n}\n",
      "type": "registry:component",
      "target": "components/review/review-13.tsx"
    },
    {
      "path": "registry/ndeko/components/review/_parts/settled-line.tsx",
      "content": "'use client';\n\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\n\ntype SettledLineProps = {\n  icon: React.ReactNode;\n  actionLabel: string;\n  actionIcon?: React.ReactNode;\n  onAction: () => void;\n  /** Shows the action held down, for a demonstration that presses it. */\n  isActionPressed?: boolean;\n  children: React.ReactNode;\n  className?: string;\n};\n\n/** What a card becomes once it is settled: one line that says what happened, and the way back. */\nexport function SettledLine({\n  icon,\n  actionLabel,\n  actionIcon,\n  onAction,\n  isActionPressed = false,\n  children,\n  className,\n}: SettledLineProps) {\n  return (\n    <div\n      className={cn(\n        'flex items-start gap-2.5 py-2.5 ps-3.5 pe-2.5 text-[13px]',\n        className\n      )}\n    >\n      <span className='mt-1 flex shrink-0 items-center'>{icon}</span>\n      <p className='min-w-0 flex-1 py-1 leading-5'>{children}</p>\n      <Button\n        type='button'\n        variant='ghost'\n        size='sm'\n        data-hand-off=''\n        onClick={onAction}\n        className={cn(\n          'text-muted-foreground shrink-0',\n          pressedQuietOf(isActionPressed)\n        )}\n      >\n        {actionIcon}\n        {actionLabel}\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/review/_parts/settled-line.tsx"
    },
    {
      "path": "registry/ndeko/components/review/_parts/use-focus-hand-off.ts",
      "content": "'use client';\n\nimport { useCallback, useEffect, useRef } from 'react';\n\n/**\n * When a card turns into another view, the control a person just used is gone and focus would fall\n * to the page. If focus was inside the card, it goes to the last element marked `data-hand-off`\n * once the new view is in place; a demonstration never had focus there, so it never moves it.\n */\nexport function useFocusHandOff(phase: string) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const isPending = useRef(false);\n\n  const markIfFocusInside = useCallback(() => {\n    const root = rootRef.current;\n    if (!root) {\n      return;\n    }\n    isPending.current = root.contains(document.activeElement);\n  }, []);\n\n  useEffect(() => {\n    if (!isPending.current) {\n      return;\n    }\n    isPending.current = false;\n    const root = rootRef.current;\n    if (!root) {\n      return;\n    }\n    const targets = root.querySelectorAll<HTMLElement>('[data-hand-off]');\n    const target = targets[targets.length - 1];\n    target?.focus();\n  }, [phase]);\n\n  return { rootRef, markIfFocusInside };\n}\n",
      "type": "registry:component",
      "target": "components/review/_parts/use-focus-hand-off.ts"
    }
  ],
  "categories": [
    "components",
    "review"
  ],
  "type": "registry:component"
}