export function relativeTime(iso: string): string {
  const diff = Date.now() - new Date(iso).getTime();
  const seconds = Math.floor(diff / 1000);
  if (seconds < 60) return "just now";
  const minutes = Math.floor(seconds / 60);
  if (minutes < 60) return `${minutes}m ago`;
  const hours = Math.floor(minutes / 60);
  if (hours < 24) return `${hours}h ago`;
  const days = Math.floor(hours / 24);
  return `${days}d ago`;
}

/**
 * relativeTime() for the recent past, a short date once it's a week old —
 * the workspace panels' list-row timestamp ("3h ago" / "Jan 15"). Two
 * panels used to carry identical copies of this.
 */
export function relativeTimeOrDate(iso: string): string {
  const d = new Date(iso);
  const days = Math.floor((Date.now() - d.getTime()) / 86_400_000);
  if (days < 7) return relativeTime(iso);
  return d.toLocaleDateString(undefined, { month: "short", day: "numeric" });
}
