"use client"; import { useState } from "react"; import Link from "next/link"; import { Pencil, Trash2, Check, X, MessageSquare, Sparkles, Hand, Upload } from "lucide-react"; import type { MemoryDTO } from "@/lib/client/types"; import { api, relTime } from "@/lib/client/fetcher"; import { Badge, Toggle, cn, toast } from "../ui"; import { CATEGORIES, categoryLabel } from "./memory-shared"; export function MemoryCard({ m, onChanged, candidate }: { m: MemoryDTO; onChanged: () => void; candidate?: boolean }) { const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(m.content); const [cat, setCat] = useState(m.category); const [busy, setBusy] = useState(false); async function patch(p: Record, msg?: string) { setBusy(true); try { await api(`/api/memories/${m.id}`, { method: "PATCH", json: p }); if (msg) toast(msg, "ok"); onChanged(); } catch (e) { toast((e as Error).message, "error"); } finally { setBusy(false); } } async function del() { if (!candidate && !confirm("Supprimer ce souvenir ?")) return; setBusy(true); try { await api(`/api/memories/${m.id}`, { method: "DELETE" }); toast(candidate ? "Candidat rejeté" : "Souvenir supprimé", "ok"); onChanged(); } finally { setBusy(false); } } const SourceIcon = m.source === "manual" ? Hand : m.source === "imported" ? Upload : Sparkles; return (
{categoryLabel(m.category)} {m.source === "manual" ? "manuel" : m.source === "imported" ? "importé" : "extrait"} {m.source_conversation_id && {m.source_title ?? "Source"}} {m.use_count > 0 && utilisé {m.use_count}×} {relTime(m.updated_at)}
{editing ? (