"use client"; import type { EntryWithTags } from "@/lib/types"; import { isWithinWeek } from "@/lib/utils/date"; interface WeeklyReflectionProps { entries: EntryWithTags[]; } export function WeeklyReflection({ entries }: WeeklyReflectionProps) { // Filter to last 7 days const weekEntries = entries.filter((e) => isWithinWeek(e.date)); if (weekEntries.length === 0) { return null; } // Count tag occurrences const tagCounts = new Map(); for (const entry of weekEntries) { for (const tag of entry.tags) { const existing = tagCounts.get(tag.id); if (existing) { existing.count++; } else { tagCounts.set(tag.id, { name: tag.name, count: 1 }); } } } // Get top 3 tags const topTags = Array.from(tagCounts.values()) .sort((a, b) => b.count - a.count) .slice(0, 3); // Generate summary let summary = ""; if (topTags.length > 0) { const tagNames = topTags.map((t) => capitalize(t.name)); if (tagNames.length === 1) { summary = `You mentioned: ${tagNames[0]}.`; } else if (tagNames.length === 2) { summary = `You mentioned: ${tagNames[0]} and ${tagNames[1]}.`; } else { summary = `You mentioned: ${tagNames.slice(0, -1).join(", ")}, and ${tagNames[tagNames.length - 1]}.`; } } return (

This week

{weekEntries.length} {weekEntries.length === 1 ? "entry" : "entries"}
{summary &&

{summary}

}
); } function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.slice(1); }