"use client"; import { Check, ChevronDown, ChevronRight, FolderOpen } from "lucide-react"; import { CalendarDays } from "lucide-react"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { formatRelativeTime } from "@/lib/relative-time"; import type { SelectGroup, SelectionUnit } from "@/lib/chat-import"; /** * Unit-level scope picker shared by the import wizard and "Edit scope". The * selection unit is the *group* (a project for Claude Code, a day for Codex): * checking a unit brings in all of its conversations and locks the agent to it, * so a later sync pulls new conversations inside chosen units and nothing else. * Sessions are shown expanded as a read-only preview — they aren't individually * selectable, which is what keeps "what I picked" and "what syncs" the same. */ export interface ScopePickerProps { groups: SelectGroup[]; unit: SelectionUnit; /** Selected group keys (cwds or `YYYY-MM-DD`). */ selected: Set; onToggle: (key: string) => void; onSelectAll: () => void; onClearAll: () => void; lang: string; } function formatDay(key: string, lang: string): string { const d = new Date(`${key}T00:00:00`); if (Number.isNaN(d.getTime())) return key; return d.toLocaleDateString(lang, { year: "numeric", month: "short", day: "numeric", weekday: "short", }); } export default function ScopePicker({ groups, unit, selected, onToggle, onSelectAll, onClearAll, lang, }: ScopePickerProps) { const { t } = useTranslation(); const [expanded, setExpanded] = useState>(new Set()); const totalSessions = groups.reduce((n, g) => n + g.sessions.length, 0); const selectedSessions = groups.reduce( (n, g) => (selected.has(g.key) ? n + g.sessions.length : n), 0, ); const GroupIcon = unit === "dates" ? CalendarDays : FolderOpen; const toggleExpand = (key: string) => setExpanded((prev) => { const next = new Set(prev); if (next.has(key)) next.delete(key); else next.add(key); return next; }); return (
{unit === "dates" ? t("{{days}} days · {{sessions}} conversations", { days: groups.length, sessions: totalSessions, }) : t("{{projects}} projects · {{sessions}} conversations", { projects: groups.length, sessions: totalSessions, })} {selectedSessions > 0 ? ( · {t("{{count}} selected", { count: selectedSessions })} ) : null}
{groups.map((group) => { const checked = selected.has(group.key); const isOpen = expanded.has(group.key); return (
{t("{{count}} chats", { count: group.sessions.length })}
{isOpen && (
    {group.sessions.map((session) => (
  • {session.provisionalTitle || t("Untitled conversation")} {formatRelativeTime(session.lastModified / 1000, lang)}
  • ))}
)}
); })}
); }