{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkpoint-rewind",
  "title": "CheckpointRewind",
  "description": "Pick a point to roll back to and see what it undoes before confirming.",
  "registryDependencies": [
    "https://creance.pages.dev/r/button.json",
    "https://creance.pages.dev/r/creance-base.json"
  ],
  "files": [
    {
      "path": "checkpoint-rewind/CheckpointRewind.css",
      "content": ".cr-rewind {\n  display: grid;\n  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));\n  align-items: start;\n  gap: var(--cr-space-6);\n  color: var(--cr-color-text-default);\n  font-family: var(--cr-font-family-sans);\n  font-size: var(--cr-font-size-md);\n}\n\n.cr-rewind__list,\n.cr-rewind__preview {\n  display: grid;\n  gap: var(--cr-space-3);\n  padding: var(--cr-space-6);\n  border-radius: var(--cr-radius-xl);\n}\n\n.cr-rewind__title {\n  margin: 0;\n  font-family: var(--cr-font-family-display);\n  font-size: var(--cr-font-size-xl);\n  font-weight: var(--cr-font-weight-bold);\n  letter-spacing: -0.015em;\n}\n\n.cr-rewind__options {\n  display: grid;\n  gap: var(--cr-space-2);\n  margin: 0;\n  padding: 0;\n  border: 0;\n}\n\n.cr-rewind__option {\n  display: flex;\n  align-items: center;\n  gap: var(--cr-space-3);\n  padding: var(--cr-space-3) 14px;\n  border-radius: 14px;\n  background: var(--cr-color-glass-tile);\n  cursor: pointer;\n}\n\n.cr-rewind__option:has(:checked) {\n  background: var(--cr-color-glass-popover);\n  box-shadow: 0 0 0 1.5px var(--cr-color-ink-bg);\n}\n\n.cr-rewind__option[data-now] {\n  cursor: default;\n}\n\n.cr-rewind__option:has(:focus-visible) {\n  outline: var(--cr-focus-width) solid var(--cr-color-focus);\n  outline-offset: var(--cr-focus-offset);\n}\n\n.cr-rewind__option input {\n  flex: none;\n  width: 18px;\n  height: 18px;\n  margin: 0;\n  accent-color: var(--cr-color-ink-bg);\n}\n\n.cr-rewind__option input:focus-visible {\n  outline: none;\n}\n\n.cr-rewind__text {\n  display: grid;\n  flex: 1;\n  gap: 2px;\n}\n\n.cr-rewind__label {\n  font-weight: var(--cr-font-weight-semibold);\n}\n\n.cr-rewind__description,\n.cr-rewind__time {\n  color: var(--cr-color-text-muted);\n  font-size: var(--cr-font-size-sm);\n}\n\n.cr-rewind__time {\n  font-variant-numeric: tabular-nums;\n}\n\n.cr-rewind__lead,\n.cr-rewind__limits {\n  margin: 0;\n  color: var(--cr-color-text-secondary);\n}\n\n.cr-rewind__limits {\n  font-size: var(--cr-font-size-sm);\n}\n\n.cr-rewind__undoes {\n  display: grid;\n  gap: var(--cr-space-2);\n  margin: 0;\n  padding: 0;\n  list-style: none;\n}\n\n.cr-rewind__undoes li {\n  display: flex;\n  justify-content: space-between;\n  gap: var(--cr-space-3);\n  padding: 10px 14px;\n  border-radius: var(--cr-radius-md);\n  background: var(--cr-color-bg-subtle);\n}\n\n.cr-rewind__undoes code {\n  font-family: var(--cr-font-family-mono);\n  font-size: 0.93em;\n}\n\n.cr-rewind__stat {\n  flex: none;\n  font-family: var(--cr-font-family-mono);\n  font-size: var(--cr-font-size-sm);\n}\n\n.cr-rewind__stat > :last-child {\n  color: var(--cr-color-diff-removed-fg);\n}\n\n.cr-rewind__actions {\n  display: flex;\n  flex-wrap: wrap;\n  gap: var(--cr-space-2);\n}\n",
      "type": "registry:file",
      "target": "@components/creance/checkpoint-rewind/CheckpointRewind.css"
    },
    {
      "path": "checkpoint-rewind/CheckpointRewind.tsx",
      "content": "'use client';\n\nimport { useId, useState, type ReactNode } from 'react';\nimport { Button } from '@/components/creance/button/Button';\nimport { cx } from '@/lib/creance/cx';\nimport './CheckpointRewind.css';\n\nexport interface Checkpoint {\n  id: string;\n  label: string;\n  description?: ReactNode;\n  /** When in the run, such as \"00:18\". */\n  time?: string;\n  /** What rewinding to this checkpoint undoes. The current point has none. */\n  undoes?: {\n    files?: { path: string; added: number; removed: number }[];\n    /** Steps that will be forgotten. */\n    steps?: string[];\n    /** Anything that is not refunded or reverted, said plainly. */\n    notes?: ReactNode[];\n  };\n}\n\nexport interface CheckpointRewindProps {\n  /** Newest first. The first is where the run is now. */\n  checkpoints: Checkpoint[];\n  onRewind: (id: string) => void;\n  onCancel?: () => void;\n  /** Said under the list of changes: what a rewind can't reach. */\n  limits?: ReactNode;\n  headingLevel?: 2 | 3 | 4;\n  className?: string;\n}\n\n/** Roll the run back. Pick a checkpoint and see exactly what will be undone before confirming. */\nexport function CheckpointRewind({\n  checkpoints,\n  onRewind,\n  onCancel,\n  limits = \"Can't be undone outside the run: anything pushed or deployed stays.\",\n  headingLevel = 3,\n  className,\n}: CheckpointRewindProps) {\n  const id = useId();\n  const H = `h${headingLevel}` as const;\n  const [picked, setPicked] = useState<string | null>(null);\n  const target = checkpoints.find((c) => c.id === picked);\n  const nowId = checkpoints[0]?.id;\n\n  return (\n    <div className={cx('cr-rewind', className)}>\n      <section aria-labelledby={`${id}-list`} className=\"cr-rewind__list cr-surface\">\n        <H id={`${id}-list`} className=\"cr-rewind__title\">\n          Checkpoints\n        </H>\n        <fieldset className=\"cr-rewind__options\">\n          <legend className=\"cr-visually-hidden\">Rewind to</legend>\n          {checkpoints.map((c) => (\n            <label key={c.id} className=\"cr-rewind__option\" data-now={c.id === nowId || undefined}>\n              <input type=\"radio\" name={id} value={c.id} checked={picked === c.id} disabled={c.id === nowId} onChange={() => setPicked(c.id)} />\n              <span className=\"cr-rewind__text\">\n                <span className=\"cr-rewind__label\">{c.id === nowId ? `Now: ${c.label}` : c.label}</span>\n                {c.description && <span className=\"cr-rewind__description\">{c.description}</span>}\n              </span>\n              {c.time && <span className=\"cr-rewind__time\">{c.time}</span>}\n            </label>\n          ))}\n        </fieldset>\n      </section>\n\n      <section aria-labelledby={`${id}-preview`} aria-live=\"polite\" className=\"cr-rewind__preview cr-glass\">\n        {target ? (\n          <>\n            <H id={`${id}-preview`} className=\"cr-rewind__title\">\n              Rewind to “{target.label}”?\n            </H>\n            <p className=\"cr-rewind__lead\">This undoes everything after {target.time ?? 'it'}:</p>\n            <ul className=\"cr-rewind__undoes\">\n              {target.undoes?.files?.map((f) => (\n                <li key={f.path}>\n                  <span>\n                    Revert changes to <code>{f.path}</code>\n                  </span>\n                  <span className=\"cr-rewind__stat\">\n                    <span aria-label={`${f.added} lines added`}>+{f.added}</span> <span aria-label={`${f.removed} lines removed`}>−{f.removed}</span>\n                  </span>\n                </li>\n              ))}\n              {target.undoes?.steps?.length ? (\n                <li>\n                  Forget {target.undoes.steps.length} {target.undoes.steps.length === 1 ? 'step' : 'steps'}: {target.undoes.steps.join(', ')}\n                </li>\n              ) : null}\n              {target.undoes?.notes?.map((n, i) => <li key={i}>{n}</li>)}\n            </ul>\n            {limits && <p className=\"cr-rewind__limits\">{limits}</p>}\n            <div className=\"cr-rewind__actions\">\n              <Button variant=\"primary\" onClick={() => onRewind(target.id)}>\n                Rewind\n              </Button>\n              <Button\n                onClick={() => {\n                  setPicked(null);\n                  onCancel?.();\n                }}\n              >\n                Cancel\n              </Button>\n            </div>\n          </>\n        ) : (\n          <>\n            <H id={`${id}-preview`} className=\"cr-rewind__title\">\n              Pick a checkpoint\n            </H>\n            <p className=\"cr-rewind__lead\">You will see what it undoes before anything changes.</p>\n          </>\n        )}\n      </section>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/creance/checkpoint-rewind/CheckpointRewind.tsx"
    }
  ],
  "categories": [
    "organism",
    "agent"
  ],
  "type": "registry:ui"
}