{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "action-history-log",
  "title": "Action History Log",
  "description": "A readable record of what your bots did: activity by hour, each action with its reason and before and after values, and Undo for the ones that can be reversed.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/action-history-log/action-history-log.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ActionKind = \"read\" | \"change\" | \"risky\";\n\nexport interface ActionChange {\n  field: string;\n  before: string;\n  after: string;\n}\n\nexport interface LoggedAction {\n  id: string;\n  /** Short time, e.g. \"14:32\". The first two digits group it by hour. */\n  time: string;\n  bot: string;\n  /** What it did, in a short sentence. */\n  action: string;\n  kind: ActionKind;\n  /** Why it did it. */\n  reason: string;\n  changes: ActionChange[];\n  /** Whether Undo is offered. */\n  reversible?: boolean;\n}\n\nexport interface ActivityHour {\n  /** Two digits, e.g. \"09\". */\n  hour: string;\n  count: number;\n}\n\nexport interface ActionHistoryLogProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  actions?: LoggedAction[];\n  activity?: ActivityHour[];\n  onUndo?: (action: LoggedAction) => void;\n}\n\ntype Filter = \"all\" | \"change\" | \"risky\";\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst ORANGE = \"#FC7840\";\nconst GREEN = \"#27A644\";\nconst RED = \"#EB5757\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst ROW = 52;\nconst CHART_H = 72;\nconst AXIS = 18;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    inset: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    bar: \"rgba(255,255,255,0.12)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    row: \"rgba(255,255,255,0.05)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    inset: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    bar: \"rgba(8,9,10,0.12)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    row: \"rgba(8,9,10,0.04)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_ACTIONS: LoggedAction[] = [\n  {\n    id: \"merge\",\n    time: \"14:32\",\n    bot: \"Patch\",\n    action: \"Merged pull request 482\",\n    kind: \"risky\",\n    reason: \"All checks passed and you approved it at 14:20.\",\n    changes: [\n      { field: \"State\", before: \"Open\", after: \"Merged\" },\n      { field: \"Branch\", before: \"billing-v2\", after: \"main\" },\n    ],\n  },\n  {\n    id: \"stock\",\n    time: \"14:18\",\n    bot: \"Relay\",\n    action: \"Updated stock on 214 products\",\n    kind: \"change\",\n    reason: \"The nightly warehouse file arrived late.\",\n    changes: [\n      { field: \"Source\", before: \"Manual\", after: \"Warehouse feed\" },\n      { field: \"Products out of stock\", before: \"31\", after: \"18\" },\n    ],\n    reversible: true,\n  },\n  {\n    id: \"notes\",\n    time: \"13:51\",\n    bot: \"Aria\",\n    action: \"Published the March release notes\",\n    kind: \"change\",\n    reason: \"You asked for them to go out before 14:00.\",\n    changes: [\n      { field: \"Status\", before: \"Draft\", after: \"Published\" },\n      { field: \"Visible to\", before: \"Team\", after: \"Everyone\" },\n    ],\n    reversible: true,\n  },\n  {\n    id: \"refund\",\n    time: \"13:20\",\n    bot: \"Tally\",\n    action: \"Refunded $84 on order 5120\",\n    kind: \"risky\",\n    reason: \"The item arrived damaged and the photo matched the order.\",\n    changes: [\n      { field: \"Refund\", before: \"None\", after: \"$84.00\" },\n      { field: \"Order status\", before: \"Delivered\", after: \"Refunded\" },\n    ],\n  },\n  {\n    id: \"tickets\",\n    time: \"11:47\",\n    bot: \"Scout\",\n    action: \"Read 40 support tickets\",\n    kind: \"read\",\n    reason: \"To find the most common reason for refunds.\",\n    changes: [{ field: \"Tickets read\", before: \"0\", after: \"40\" }],\n  },\n  {\n    id: \"dupes\",\n    time: \"10:05\",\n    bot: \"Sift\",\n    action: \"Closed 12 duplicate tickets\",\n    kind: \"change\",\n    reason: \"Each one matched an open ticket from the same customer.\",\n    changes: [\n      { field: \"Status\", before: \"Open\", after: \"Closed\" },\n      { field: \"Open tickets\", before: \"158\", after: \"146\" },\n    ],\n    reversible: true,\n  },\n  {\n    id: \"pool\",\n    time: \"09:12\",\n    bot: \"Patch\",\n    action: \"Changed a setting on staging\",\n    kind: \"risky\",\n    reason: \"To reproduce a timeout before the release.\",\n    changes: [{ field: \"db.pool.max\", before: \"100\", after: \"40\" }],\n    reversible: true,\n  },\n];\n\nconst DEFAULT_ACTIVITY: ActivityHour[] = [\n  { hour: \"09\", count: 18 },\n  { hour: \"10\", count: 34 },\n  { hour: \"11\", count: 52 },\n  { hour: \"12\", count: 21 },\n  { hour: \"13\", count: 46 },\n  { hour: \"14\", count: 61 },\n  { hour: \"15\", count: 12 },\n];\n\nconst FILTERS: { id: Filter; label: string }[] = [\n  { id: \"all\", label: \"All\" },\n  { id: \"change\", label: \"Changes\" },\n  { id: \"risky\", label: \"Risky\" },\n];\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle\n        cx={r}\n        cy={r}\n        r={r}\n        className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n        style={{ fill: color }}\n      />\n    </svg>\n  );\n}\n\nfunction useWidth<T extends HTMLElement>(fallback: number) {\n  const ref = React.useRef<T>(null);\n  const [width, setWidth] = React.useState(fallback);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => {\n      setWidth(Math.round(entry.contentRect.width));\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, width] as const;\n}\n\nexport function ActionHistoryLog({\n  theme = \"dark\",\n  title = \"Action history\",\n  actions = DEFAULT_ACTIONS,\n  activity = DEFAULT_ACTIVITY,\n  onUndo,\n  className,\n  style,\n  ...rest\n}: ActionHistoryLogProps) {\n  const c = PALETTES[theme];\n  const [filter, setFilter] = React.useState<Filter>(\"all\");\n  const [hour, setHour] = React.useState<string | null>(null);\n  const [selected, setSelected] = React.useState(actions[0]?.id ?? \"\");\n  const [undone, setUndone] = React.useState<string[]>([]);\n  const [chartRef, width] = useWidth<HTMLDivElement>(820);\n\n  const total = activity.reduce((sum, a) => sum + a.count, 0);\n  const peak = Math.max(...activity.map((a) => a.count), 1);\n  const matches = (a: LoggedAction, f: Filter, h: string | null) =>\n    (f === \"all\" || a.kind === f) && (!h || a.time.startsWith(h));\n  const shown = actions.filter((a) => matches(a, filter, hour));\n  const count = (f: Filter) =>\n    actions.filter((a) => matches(a, f, hour)).length;\n\n  const colorOf = (a: LoggedAction) =>\n    undone.includes(a.id)\n      ? c.faint\n      : a.kind === \"risky\"\n        ? ORANGE\n        : a.kind === \"change\"\n          ? ACCENT\n          : c.faint;\n\n  const refocus = (f: Filter, h: string | null) => {\n    const list = actions.filter((a) => matches(a, f, h));\n    if (list[0] && !list.some((a) => a.id === selected)) {\n      setSelected(list[0].id);\n    }\n  };\n\n  const pickFilter = (f: Filter) => {\n    setFilter(f);\n    refocus(f, hour);\n  };\n\n  const pickHour = (h: string) => {\n    const next = hour === h ? null : h;\n    setHour(next);\n    refocus(filter, next);\n  };\n\n  const undo = (a: LoggedAction) => {\n    setUndone((prev) => [...prev, a.id]);\n    onUndo?.(a);\n  };\n\n  const slot = width / Math.max(activity.length, 1);\n  const barW = Math.max(8, Math.min(44, Math.round(slot - 10)));\n  const base = CHART_H - AXIS;\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-3 @2xl:p-6 @2xl:pb-3\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h3 className=\"m-0 text-[20px] leading-[26px] font-[590] tracking-[-0.012em]\">\n              {title}\n            </h3>\n            <p\n              className=\"m-0 mt-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              The actions that matter, most recent first.\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\">\n              {(hour\n                ? (activity.find((a) => a.hour === hour)?.count ?? 0)\n                : total\n              ).toLocaleString(\"en-US\")}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              {hour ? `Actions at ${hour}:00` : \"Actions today\"}\n            </p>\n          </div>\n        </div>\n\n        <div ref={chartRef} className=\"mt-2 w-full\" style={{ height: CHART_H }}>\n          <svg\n            role=\"group\"\n            aria-label=\"Actions per hour\"\n            width={width}\n            height={CHART_H}\n            className=\"block\"\n          >\n            <line\n              x1={0}\n              x2={width}\n              y1={base + 0.5}\n              y2={base + 0.5}\n              stroke={c.grid}\n            />\n            {activity.map((a, i) => {\n              const cx = Math.round(slot * i + slot / 2);\n              const h = Math.max(3, Math.round((a.count / peak) * (base - 4)));\n              const on = hour === a.hour;\n              return (\n                <g\n                  key={a.hour}\n                  data-hour={a.hour}\n                  role=\"button\"\n                  tabIndex={0}\n                  aria-pressed={on}\n                  aria-label={`${a.hour}:00, ${a.count} actions`}\n                  onClick={() => pickHour(a.hour)}\n                  onKeyDown={(e) => {\n                    if (e.key === \"Enter\" || e.key === \" \") {\n                      e.preventDefault();\n                      pickHour(a.hour);\n                    }\n                  }}\n                  className=\"cursor-pointer outline-none [&:focus-visible>rect:nth-child(2)]:[stroke-width:2] [&:focus-visible>rect:nth-child(2)]:[stroke:#F7F8F8]\"\n                >\n                  <rect\n                    x={Math.round(slot * i)}\n                    y={0}\n                    width={Math.round(slot)}\n                    height={CHART_H}\n                    fill=\"transparent\"\n                  />\n                  <rect\n                    x={cx - barW / 2}\n                    y={base - h}\n                    width={barW}\n                    height={h}\n                    rx=\"3\"\n                    fill={on || !hour ? ACCENT : c.bar}\n                    opacity={on || !hour ? 1 : 0.9}\n                    className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n                  />\n                  <text\n                    x={cx}\n                    y={CHART_H - 3}\n                    textAnchor=\"middle\"\n                    fontSize=\"11\"\n                    fill={on ? c.text : c.faint}\n                    style={{ fontVariantNumeric: \"tabular-nums\" }}\n                  >\n                    {a.hour}:00\n                  </text>\n                </g>\n              );\n            })}\n          </svg>\n        </div>\n\n        <div role=\"group\" aria-label=\"Filter\" className=\"mt-3 flex gap-1.5\">\n          {FILTERS.map((f) => {\n            const on = filter === f.id;\n            return (\n              <button\n                key={f.id}\n                type=\"button\"\n                data-filter={f.id}\n                aria-pressed={on}\n                onClick={() => pickFilter(f.id)}\n                className={`flex h-7 cursor-pointer items-center gap-2 rounded-full border-0 px-3 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                style={{\n                  background: on ? c.chip : \"transparent\",\n                  color: on ? c.text : c.sub,\n                }}\n              >\n                {f.id !== \"all\" && (\n                  <Dot size={8} color={f.id === \"risky\" ? ORANGE : ACCENT} />\n                )}\n                {f.label}\n                <span className=\"tabular-nums\" style={{ color: c.sub }}>\n                  {count(f.id)}\n                </span>\n              </button>\n            );\n          })}\n        </div>\n      </div>\n\n      <div\n        className=\"grid border-t @2xl:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)]\"\n        style={{ borderColor: c.border }}\n      >\n        {/* Rows slide into place, so filtering never changes the card's height. */}\n        <div className=\"p-2\">\n          <ul\n            className=\"relative m-0 list-none overflow-hidden p-0\"\n            style={{ height: actions.length * ROW }}\n          >\n            {!shown.length && (\n              <li\n                className=\"flex h-full items-center justify-center text-[13px] leading-[20px] tracking-[-0.011em]\"\n                style={{ color: c.faint }}\n              >\n                No notable actions here.\n              </li>\n            )}\n            {actions.map((a) => {\n              const at = shown.indexOf(a);\n              const on = at >= 0;\n              const off = undone.includes(a.id);\n              return (\n                <li\n                  key={a.id}\n                  aria-hidden={!on}\n                  inert={!on}\n                  className=\"motion-safe:transition-[transform,opacity] motion-safe:duration-300\"\n                  style={{\n                    position: \"absolute\",\n                    top: 0,\n                    left: 0,\n                    right: 0,\n                    height: ROW,\n                    opacity: on ? 1 : 0,\n                    visibility: on ? \"visible\" : \"hidden\",\n                    transform: `translateY(${(on ? at : actions.indexOf(a)) * ROW}px)`,\n                  }}\n                >\n                  <button\n                    type=\"button\"\n                    data-action={a.id}\n                    aria-current={selected === a.id ? \"true\" : undefined}\n                    onClick={() => setSelected(a.id)}\n                    className={`flex size-full cursor-pointer items-center gap-2.5 rounded-lg border-0 bg-transparent px-3 text-left motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                    style={{\n                      background: selected === a.id ? c.row : \"transparent\",\n                    }}\n                  >\n                    <Dot size={8} color={colorOf(a)} />\n                    <span className=\"min-w-0 flex-1\">\n                      <span\n                        className=\"block truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                        style={{ color: off ? c.sub : c.text }}\n                      >\n                        {a.action}\n                      </span>\n                      <span\n                        className=\"block truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                        style={{ color: c.faint }}\n                      >\n                        {off ? `${a.bot}, undone` : a.bot}\n                      </span>\n                    </span>\n                    <span\n                      className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em] tabular-nums\"\n                      style={{ color: c.faint }}\n                    >\n                      {a.time}\n                    </span>\n                  </button>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n\n        {/* Every action's details share one cell, so picking one never changes the height. */}\n        <div\n          className=\"grid border-t p-5 @2xl:border-t-0 @2xl:border-l\"\n          style={{ borderColor: c.border }}\n        >\n          {actions.map((a) => {\n            const on = a.id === selected && shown.length > 0;\n            const off = undone.includes(a.id);\n            return (\n              <article\n                key={a.id}\n                aria-hidden={!on}\n                inert={!on}\n                className={`flex min-w-0 flex-col [grid-area:1/1] motion-safe:transition-opacity motion-safe:duration-200 ${on ? \"visible opacity-100\" : \"invisible opacity-0\"}`}\n              >\n                <h4 className=\"m-0 text-[16px] leading-[22px] font-[590] tracking-[-0.014em]\">\n                  {a.action}\n                </h4>\n                <p\n                  className=\"m-0 mt-0.5 text-[12px] leading-[16px] tracking-[-0.005em] tabular-nums\"\n                  style={{ color: c.faint }}\n                >\n                  {a.bot} at {a.time}\n                </p>\n                <p\n                  className=\"m-0 mt-3 text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n                  style={{ color: c.soft, minHeight: 40 }}\n                >\n                  {a.reason}\n                </p>\n                <dl className=\"m-0 mt-3\">\n                  {a.changes.map((ch) => (\n                    <div\n                      key={ch.field}\n                      className=\"border-t py-2\"\n                      style={{ borderColor: c.border }}\n                    >\n                      <dt\n                        className=\"text-[12px] leading-[16px] tracking-[-0.005em]\"\n                        style={{ color: c.faint }}\n                      >\n                        {ch.field}\n                      </dt>\n                      <dd className=\"m-0 mt-0.5 flex min-w-0 items-center gap-2 text-[13px] leading-[20px] tracking-[-0.011em] tabular-nums\">\n                        <span\n                          className=\"truncate line-through\"\n                          style={{ color: off ? c.text : RED }}\n                        >\n                          {ch.before}\n                        </span>\n                        <span aria-hidden=\"true\" style={{ color: c.faint }}>\n                          →\n                        </span>\n                        <span\n                          className=\"truncate\"\n                          style={{ color: off ? c.faint : GREEN }}\n                        >\n                          {ch.after}\n                        </span>\n                      </dd>\n                    </div>\n                  ))}\n                </dl>\n                <div className=\"mt-auto pt-3\">\n                  <button\n                    type=\"button\"\n                    data-undo=\"\"\n                    tabIndex={on ? 0 : -1}\n                    disabled={!a.reversible || off}\n                    onClick={() => undo(a)}\n                    className={`h-9 w-full cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n                    style={{\n                      background: a.reversible && !off ? c.btn : c.chip,\n                      color: a.reversible && !off ? c.btnText : c.faint,\n                    }}\n                  >\n                    {off\n                      ? \"Undone\"\n                      : a.reversible\n                        ? \"Undo this action\"\n                        : \"Can't be undone\"}\n                  </button>\n                </div>\n              </article>\n            );\n          })}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}