import { formatDateInTimezone, type FormatDateInTimezoneOptions } from "@/utils/formatters";

export const formatRelativeTime = (dateStr: string, timezone: string, options?: FormatDateInTimezoneOptions): string => {
  const now = Date.now();
  const then = new Date(dateStr).getTime();
  const diffMs = now - then;
  const diffSecs = Math.floor(diffMs / 1000);
  const diffMins = Math.floor(diffSecs / 60);
  const diffHours = Math.floor(diffMins / 60);

  if (diffSecs < 60) return `${diffSecs}s ago`;
  if (diffMins < 60) return `${diffMins}m ago`;
  if (diffHours < 24) return `${diffHours}h ago`;
  return formatDateInTimezone(dateStr, timezone, options);
};
