import { displayScore, type ForumThread } from "@/lib/forumState"; export type ForumSortMode = "hot" | "new" | "top"; function hoursSince(ts: number): number { return (Date.now() - ts) / 3600000; } export function hotRank(t: ForumThread): number { const s = displayScore(t); const engagement = t.replies.length * 4; const freshness = Math.max(0, 72 - hoursSince(t.ts)) * 2; return s + engagement + freshness; } export function sortThreads(list: ForumThread[], mode: ForumSortMode): ForumThread[] { const copy = [...list]; if (mode === "new") copy.sort((a, b) => b.ts - a.ts); else if (mode === "top") copy.sort((a, b) => displayScore(b) - displayScore(a)); else copy.sort((a, b) => hotRank(b) - hotRank(a)); return copy; }