export const pwaNotificationTypeLabels = {
  task_assigned: 'تسک جدید',
  task_new: 'تسک جدید',
  task_created: 'تسک جدید',
  comment_created: 'کامنت جدید',
  comment_new: 'کامنت جدید',
  mention: 'منشن',
  deadline_soon: 'نزدیک شدن ددلاین',
  task_overdue: 'تسک عقب‌افتاده',
  task_status_changed: 'تغییر وضعیت تسک',
  system: 'پیام سیستمی',
};

export function getPwaNotificationTitle(notification) {
  return notification?.title || pwaNotificationTypeLabels[notification?.type] || 'اعلان جدید';
}

export function getPwaNotificationMessage(notification) {
  return notification?.message || notification?.body || 'جزئیات بیشتری برای این اعلان ثبت نشده است.';
}

export function getPwaNotificationTarget(notification) {
  const data = notification?.data || {};
  const targetType = notification?.targetType || notification?.target_type || data.targetType || data.target_type;
  const targetId = notification?.targetId || notification?.target_id || data.targetId || data.target_id;
  const notifiableType = notification?.notifiable_type || data.notifiable_type || '';
  const notifiableId = notification?.notifiable_id || data.notifiable_id;
  const taskId = data.task_id || data.taskId || (targetType === 'task' ? targetId : null) || (notifiableType.includes('Task') ? notifiableId : null);
  const projectId = data.project_id || data.projectId || (targetType === 'project' ? targetId : null) || (notifiableType.includes('Project') ? notifiableId : null);

  if (targetType === 'task' || taskId) return { path: taskId ? `/pwa/tasks/${taskId}` : '/pwa/tasks', available: true };
  if (targetType === 'project' || projectId) return { path: projectId ? `/pwa/projects/${projectId}` : '/pwa/projects', available: true };
  if (targetType === 'comment' && taskId) return { path: `/pwa/tasks/${taskId}`, available: true };

  return { path: null, available: false };
}
