import useDateFormat from "../../../../../hooks/useDateFormat/index.js";
import useNowInterval from "../../../../../hooks/time/useNowInterval/index.js";
const useFormattedTimestamp = function useFormattedTimestamp(timestamp) {
  const formatted = useDateFormat(timestamp);
  const now = useNowInterval(30000);
  if (!now) return formatted;
  const diffMs = now - new Date(timestamp);

  // Handle minutes-old formats
  const diffMins = Math.round(diffMs / (1000 * 60));
  if (diffMins < 1) return 'Just now';
  if (diffMins < 2) return '1 minute ago';
  if (diffMins < 60) return `${diffMins} minutes ago`;

  // Handle hours-old formats
  const diffHrs = Math.round(diffMins / 60);
  if (diffHrs < 2) return '1 hour ago';
  if (diffHrs < 24) return `${diffHrs} hours ago`;

  // Fall back to full timestamp
  return formatted;
};
export default useFormattedTimestamp;