export function formatPwaNotificationTime(value) {
  if (!value) return 'همین الان';
  const date = new Date(value);
  const diffMs = Date.now() - date.getTime();
  const diffMinutes = Math.max(0, Math.floor(diffMs / 60000));

  if (diffMinutes < 1) return 'همین الان';
  if (diffMinutes < 60) return `${diffMinutes.toLocaleString('fa-IR')} دقیقه پیش`;

  const diffHours = Math.floor(diffMinutes / 60);
  if (diffHours < 6) return `${diffHours.toLocaleString('fa-IR')} ساعت پیش`;

  const today = new Date();
  const yesterday = new Date();
  yesterday.setDate(today.getDate() - 1);
  const sameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();

  if (sameDay(date, today)) return 'امروز';
  if (sameDay(date, yesterday)) return 'دیروز';
  return date.toLocaleDateString('fa-IR');
}
