import { cn } from "../../src/lib/utils";
import { Plus, MessageSquare, ChevronLeft, ChevronRight } from "lucide-react";
import { useState } from "react";
import type { SessionListItem } from "../../src/lib/types";
// =============================================================================
// 会话侧边栏 — Anthropic 分段式:今天/昨天/更早 + 橙色活跃态
// =============================================================================
interface SessionSidebarProps {
sessions: SessionListItem[];
activeId?: string | null;
onSelect?: (id: string) => void;
onNew?: () => void;
className?: string;
}
export function SessionSidebar({
sessions,
activeId,
onSelect,
onNew,
className,
}: SessionSidebarProps) {
const [collapsed, setCollapsed] = useState(false);
// 按日期分组
const groups = groupByRecency(sessions);
return (
{/* 头部 */}
{!collapsed && (
会话
)}
{!collapsed && onNew && (
)}
{/* 会话列表 — 分段 */}
{!collapsed && (
)}
);
}
// =============================================================================
// 按日期分组
// =============================================================================
interface SessionGroup {
label: string;
sessions: SessionListItem[];
}
function groupByRecency(sessions: SessionListItem[]): SessionGroup[] {
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const yesterday = new Date(today.getTime() - 86400000);
const groups: SessionGroup[] = [
{ label: "今天", sessions: [] },
{ label: "昨天", sessions: [] },
{ label: "更早", sessions: [] },
];
for (const session of sessions) {
const date = session.updatedAt ? new Date(session.updatedAt) : new Date(0);
if (date >= today) {
groups[0].sessions.push(session);
} else if (date >= yesterday) {
groups[1].sessions.push(session);
} else {
groups[2].sessions.push(session);
}
}
return groups.filter((g) => g.sessions.length > 0);
}