"use client"; import { useEffect, useState } from "react"; import { Brain, Check, FileText, ScrollText } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { LucideIcon } from "lucide-react"; import PickerShell from "@/components/common/PickerShell"; import PickerHeader from "@/components/common/PickerHeader"; import type { SpaceMemoryFile } from "@/lib/space-items"; interface MemoryPickerProps { open: boolean; initialFiles: SpaceMemoryFile[]; onClose: () => void; onApply: (files: SpaceMemoryFile[]) => void; } interface MemoryOption { key: SpaceMemoryFile; label: string; description: string; icon: LucideIcon; } const MEMORY_OPTIONS: MemoryOption[] = [ { key: "summary", label: "Summary", description: "Inject the assistant's running summary of past learning sessions.", icon: ScrollText, }, { key: "profile", label: "Profile", description: "Inject the learner profile (preferences, goals, background).", icon: FileText, }, ]; export default function MemoryPicker({ open, initialFiles, onClose, onApply, }: MemoryPickerProps) { const { t } = useTranslation(); const [selected, setSelected] = useState(initialFiles); // IIFE keeps the setState call out of the synchronous effect body to // satisfy `react-hooks/set-state-in-effect`. useEffect(() => { if (!open) return; let cancelled = false; void (async () => { if (cancelled) return; setSelected(initialFiles); })(); return () => { cancelled = true; }; }, [open, initialFiles]); const toggle = (key: SpaceMemoryFile) => { setSelected((prev) => prev.includes(key) ? prev.filter((item) => item !== key) : [...prev, key], ); }; const handleApply = () => { onApply(selected); onClose(); }; return (
{MEMORY_OPTIONS.map((option) => { const active = selected.includes(option.key); const Icon = option.icon; return ( ); })}
{selected.length === 1 ? t("1 memory artifact selected") : t("{{n}} memory artifacts selected", { n: selected.length })}
); }