export const resolveNotificationImageUrl = (content) => {
  if (!content) return null;
  const media = content.media?.[0]?.url;
  if (media) return media;
  const direct = content.image_url;
  if (!direct) return null;
  if (direct.startsWith("http")) return direct;
  const base = (process.env.API_URL ?? "").replace(/\/$/, "");
  return `${base}/${direct.replace(/^\//, "")}`;
};

export const formatNotificationDate = (dateStr, todayLabel) => {
  if (!dateStr) return "";
  const date = new Date(dateStr);
  const today = new Date();
  const isToday =
    date.getDate() === today.getDate() &&
    date.getMonth() === today.getMonth() &&
    date.getFullYear() === today.getFullYear();
  if (isToday) return todayLabel;
  return date.toLocaleDateString("pt-BR", { day: "2-digit", month: "2-digit", year: "numeric" });
};
