import type { ChatSession, Theme } from "@/types";
import { THEMES } from "@/lib/constants";
interface HistoryViewProps {
theme: (typeof THEMES)[Theme];
sessions: ChatSession[];
sortedSessions: ChatSession[];
viewingHistory: ChatSession | null;
onView: (session: ChatSession) => void;
onBack: () => void;
onOpen: (id: string) => void;
onDelete: (id: string) => void;
onPin: (id: string) => void;
onClearAll: () => void;
}
export function HistoryView({
theme, sessions, sortedSessions, viewingHistory,
onView, onBack, onOpen, onDelete, onPin, onClearAll,
}: HistoryViewProps) {
// ── Drill-down: single session reader ─────────────────────────────────────
if (viewingHistory) {
return (
{viewingHistory.title}
{new Date(viewingHistory.updatedAt).toLocaleString()} · {viewingHistory.messages.length} messages
{viewingHistory.messages.map((msg) => (
))}
);
}
// ── Session list ──────────────────────────────────────────────────────────
return (
Conversation History
{sessions.length} saved session{sessions.length !== 1 ? "s" : ""}
{sessions.length > 0 && (
)}
{/* Empty state */}
{sessions.length === 0 ? (
🕐
No history yet
Conversations are saved automatically
) : (
{sortedSessions.map((session) => (
onView(session)}
className="group relative rounded-xl p-4 cursor-pointer transition-all border hover:bg-white/[0.04]"
style={{ background: "rgba(255,255,255,0.02)", borderColor: theme.border }}>
{session.pinned &&
📌}
{session.title}
{session.preview}
{new Date(session.updatedAt).toLocaleDateString("en-GB", { day: "numeric", month: "short" })}
·
{session.messages.length} messages
{/* Hover actions */}
))}
)}
);
}