"use client"; import { Sparkles } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import type { DreamActionRecord, DreamActionType } from "@/types/memory"; import { cn } from "@/lib/utils"; import { useI18n } from "@/i18n/i18n-context"; interface ApplyConfirmDialogProps { open: boolean; onOpenChange: (open: boolean) => void; memoryStoreName: string; selected: DreamActionRecord[]; onConfirm: () => void; busy: boolean; } const ACTION_CLASS: Record = { ADD: "bg-success-soft text-success", UPDATE: "bg-info-soft text-info", DELETE: "bg-danger-soft text-danger", MERGE: "bg-[hsl(var(--primary-soft))] text-[hsl(var(--primary))]", NOOP: "bg-muted text-muted-foreground", EMIT_SKILL: "bg-success-soft text-success", EMIT_PROFILE: "bg-[hsl(var(--primary-soft))] text-[hsl(var(--primary))]", }; const PREVIEW_LIMIT = 6; /** * Confirmation modal that shows *what* the user is about to apply, not just * a count. The most common foot-gun with multi-select bulk operations is * the user mis-selecting one row in a long table; previewing the first * handful of rows turns the confirmation into a real review step. * * Action mix summary (e.g. "ADD 2 / UPDATE 1 / DELETE 3") goes at the top * because the destructive count (DELETE) is the single most useful signal * for whether the user wants to keep going. */ export function MemoryDreamApplyConfirmDialog({ open, onOpenChange, memoryStoreName, selected, onConfirm, busy, }: ApplyConfirmDialogProps) { const { t } = useI18n(); const counts: Partial> = {}; for (const a of selected) counts[a.action] = (counts[a.action] ?? 0) + 1; const hasDestructive = (counts.DELETE ?? 0) > 0; const preview = selected.slice(0, PREVIEW_LIMIT); const remaining = selected.length - preview.length; return ( {t("memory.dream.apply.title")} {t("memory.dream.apply.descPrefix")}{" "} {memoryStoreName}{" "} {t("memory.dream.apply.descSuffix", { count: selected.length })}
{(Object.keys(counts) as DreamActionType[]).map((type) => ( {type}{" "} ×{counts[type]} ))}
{hasDestructive && (

{t("memory.dream.apply.hasDestructive")}

)}
    {preview.map((action) => (
  • {action.action} {action.newMemory?.text ?? action.reason ?? `(${action.actionId.slice(0, 12)}…)`}
  • ))} {remaining > 0 && (
  • {t("memory.dream.apply.remaining", { count: remaining })}
  • )}
); }