{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "audit-log",
  "title": "Audit Log",
  "description": "A timestamped activity log block for registry and product events.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/corr/components/audit-log.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ExternalLink, FileSearch, MoreHorizontal } from \"lucide-react\"\n\nimport {\n  ContextMenu,\n  ContextMenuContent,\n  ContextMenuItem,\n  ContextMenuSeparator,\n  ContextMenuTrigger,\n} from \"@/components/ui/context-menu\"\nimport { cn } from \"@/lib/utils\"\nimport {\n  Filters,\n  type Filter,\n  type FilterFieldConfig,\n  type FilterFieldsConfig,\n} from \"./filters\"\n\nexport type AuditLogItem = {\n  id: string\n  title: string\n  description?: string\n  timestamp: string\n  actor?: string\n  type?: string\n  status?: string\n  icon?: React.ReactNode\n}\n\nconst auditLogFilterFields: FilterFieldConfig<string>[] = [\n  {\n    key: \"actor\",\n    label: \"Actor\",\n    type: \"select\",\n    options: [],\n  },\n  {\n    key: \"type\",\n    label: \"Type\",\n    type: \"select\",\n    options: [],\n  },\n  {\n    key: \"status\",\n    label: \"Status\",\n    type: \"select\",\n    options: [],\n  },\n  {\n    key: \"search\",\n    label: \"Search\",\n    type: \"text\",\n    defaultOperator: \"contains\",\n    placeholder: \"Search events\",\n  },\n]\n\nfunction uniqueOptions(\n  items: AuditLogItem[],\n  key: \"actor\" | \"type\" | \"status\"\n) {\n  return Array.from(\n    new Set(items.map((item) => item[key]).filter(Boolean) as string[])\n  )\n    .sort()\n    .map((value) => ({ value, label: value }))\n}\n\nfunction matchesFilter(item: AuditLogItem, filter: Filter<string>) {\n  if (filter.operator === \"empty\") return true\n  if (filter.operator === \"not_empty\") return true\n\n  const expected = filter.values.filter(Boolean)\n  if (expected.length === 0) return true\n\n  if (filter.field === \"search\") {\n    const haystack = [\n      item.title,\n      item.description,\n      item.actor,\n      item.type,\n      item.status,\n    ]\n      .filter(Boolean)\n      .join(\" \")\n      .toLowerCase()\n    const needle = expected[0]?.toLowerCase() ?? \"\"\n\n    return filter.operator === \"not_contains\"\n      ? !haystack.includes(needle)\n      : haystack.includes(needle)\n  }\n\n  const value = String(item[filter.field as \"actor\" | \"type\" | \"status\"] ?? \"\")\n\n  if (filter.operator === \"is_not\" || filter.operator === \"is_not_any_of\") {\n    return !expected.includes(value)\n  }\n\n  return expected.includes(value)\n}\n\nexport function AuditLog({\n  items,\n  enableFilters = true,\n  onOpenRecord,\n  onReviewChange,\n  className,\n}: {\n  items: AuditLogItem[]\n  enableFilters?: boolean\n  onOpenRecord?: (item: AuditLogItem) => void\n  onReviewChange?: (item: AuditLogItem) => void\n  className?: string\n}) {\n  const [filters, setFilters] = React.useState<Filter<string>[]>([])\n\n  const fields = React.useMemo<FilterFieldsConfig<string>>(\n    () =>\n      auditLogFilterFields.map((field) => {\n        if (field.key === \"actor\") {\n          return { ...field, options: uniqueOptions(items, \"actor\") }\n        }\n        if (field.key === \"type\") {\n          return { ...field, options: uniqueOptions(items, \"type\") }\n        }\n        if (field.key === \"status\") {\n          return { ...field, options: uniqueOptions(items, \"status\") }\n        }\n        return field\n      }),\n    [items]\n  )\n\n  const visibleItems = React.useMemo(\n    () =>\n      items.filter((item) =>\n        filters.every((filter) => matchesFilter(item, filter))\n      ),\n    [filters, items]\n  )\n\n  return (\n    <div className={cn(\"grid gap-3\", className)}>\n      {enableFilters ? (\n        <Filters\n          filters={filters}\n          fields={fields}\n          onChange={setFilters}\n          size=\"sm\"\n          allowMultiple={false}\n        />\n      ) : null}\n\n      <div className=\"rounded-md border bg-card\">\n        {visibleItems.length > 0 ? (\n          visibleItems.map((item, index) => (\n            <ContextMenu key={item.id}>\n              <ContextMenuTrigger asChild>\n                <div className=\"relative flex gap-3 px-4 py-3\">\n                  {index < visibleItems.length - 1 ? (\n                    <div className=\"absolute top-9 bottom-0 left-[1.55rem] w-px bg-border\" />\n                  ) : null}\n                  <div className=\"z-1 flex size-5 shrink-0 items-center justify-center rounded-full border bg-background text-muted-foreground\">\n                    {item.icon}\n                  </div>\n                  <div className=\"min-w-0 flex-1\">\n                    <div className=\"flex flex-wrap items-center justify-between gap-2\">\n                      <div className=\"text-sm font-medium\">{item.title}</div>\n                      <div className=\"text-xs text-muted-foreground\">\n                        {item.timestamp}\n                      </div>\n                    </div>\n                    {item.description ? (\n                      <div className=\"mt-1 text-xs leading-5 text-muted-foreground\">\n                        {item.description}\n                      </div>\n                    ) : null}\n                    <div className=\"mt-2 flex flex-wrap items-center gap-2 text-xs\">\n                      {item.actor ? (\n                        <span className=\"font-medium\">{item.actor}</span>\n                      ) : null}\n                      {item.type ? (\n                        <span className=\"rounded-full border px-2 py-0.5 text-muted-foreground\">\n                          {item.type}\n                        </span>\n                      ) : null}\n                      {item.status ? (\n                        <span className=\"rounded-full border px-2 py-0.5 text-muted-foreground\">\n                          {item.status}\n                        </span>\n                      ) : null}\n                    </div>\n                  </div>\n                </div>\n              </ContextMenuTrigger>\n              <ContextMenuContent className=\"w-44\">\n                <ContextMenuItem onSelect={() => onOpenRecord?.(item)}>\n                  <ExternalLink />\n                  Open record\n                </ContextMenuItem>\n                <ContextMenuItem onSelect={() => onReviewChange?.(item)}>\n                  <FileSearch />\n                  Review change\n                </ContextMenuItem>\n                <ContextMenuSeparator />\n                <ContextMenuItem>\n                  <MoreHorizontal />\n                  Copy record ID\n                </ContextMenuItem>\n              </ContextMenuContent>\n            </ContextMenu>\n          ))\n        ) : (\n          <div className=\"px-4 py-8 text-center text-sm text-muted-foreground\">\n            No audit log items match these filters.\n          </div>\n        )}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}