// TODO: add a barrel import here ffs import type { HistoryCard, HistoryCategory } from '@/lib/history/types' export function mergeAndSort(cards: HistoryCard[][]): HistoryCard[] { return cards .flat() .sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()) } export function groupByDate( cards: HistoryCard[], now: Date = new Date(), ): Record { return cards.reduce>((acc, card) => { const date = new Date(card.timestamp); const includeYear = date.getFullYear() !== now.getFullYear(); const key = date.toLocaleDateString('pt-BR', { weekday: 'long', day: 'numeric', month: 'long', ...(includeYear ? { year: 'numeric' } : {}), }); (acc[key] ??= []).push(card) return acc }, {}) } export function filterByCategory( cards: HistoryCard[], active: HistoryCategory | 'all', ): HistoryCard[] { if (active === 'all') return cards return cards.filter(c => c.category === active) }