// The order of the Notes page (plan step 6.13b), unit-tested in tests/crm.test.mjs. /** Pinned notes first, then the rest; each newest-edited first. */ export function splitNotes(notes) { const newest = (a, b) => String(b.updated_at ?? b.created_at).localeCompare(String(a.updated_at ?? a.created_at)) return { pinned: notes.filter(n => n.is_pinned).sort(newest), rest: notes.filter(n => !n.is_pinned).sort(newest) } } /** To-dos not done (urgent first, then newest) and done ones (most recently done first). */ export function splitTodos(todos) { const open = todos.filter(t => !t.is_done).sort((a, b) => (a.priority === 'high' ? 0 : 1) - (b.priority === 'high' ? 0 : 1) || String(b.created_at).localeCompare(String(a.created_at))) const done = todos.filter(t => t.is_done).sort((a, b) => String(b.done_at ?? '').localeCompare(String(a.done_at ?? ''))) return { open, done } }