export const NOTIFICATION_SWIPE_DISMISS_DISTANCE = 72;
export const NOTIFICATION_SWIPE_MAX_OFFSET = 64;
const NOTIFICATION_SWIPE_SLOP = 8;
const NOTIFICATION_SWIPE_HORIZONTAL_DOMINANCE = 1.5;

function hasHorizontalIntent(deltaX, deltaY) {
  return Math.abs(deltaX) >= Math.abs(deltaY) * NOTIFICATION_SWIPE_HORIZONTAL_DOMINANCE;
}

export function notificationSwipeAxis(deltaX, deltaY) {
  const horizontalDistance = Math.abs(deltaX);
  const verticalDistance = Math.abs(deltaY);
  if (Math.max(horizontalDistance, verticalDistance) < NOTIFICATION_SWIPE_SLOP) return null;
  return hasHorizontalIntent(deltaX, deltaY) ? "horizontal" : "vertical";
}

export function notificationSwipeOffset(deltaX, axis, width) {
  if (axis !== "horizontal" || deltaX >= 0) return 0;
  const limit = Number.isFinite(width) && width > 0
    ? Math.min(width, NOTIFICATION_SWIPE_MAX_OFFSET)
    : NOTIFICATION_SWIPE_MAX_OFFSET;
  return Math.max(-limit, deltaX);
}

export function shouldDismissNotificationSwipe(deltaX, deltaY) {
  return deltaX <= -NOTIFICATION_SWIPE_DISMISS_DISTANCE && hasHorizontalIntent(deltaX, deltaY);
}
