export const isKey = (e: KeyboardEvent | React.KeyboardEvent, key: string): boolean => {
  return e.key.toLowerCase() === key.toLowerCase()
}

export const isModifierKey = (e: KeyboardEvent | React.KeyboardEvent): boolean => {
  return e.ctrlKey || e.metaKey || e.altKey
}

export const getMouseClickPosition = (e: React.MouseEvent | MouseEvent) => {
  return {
    x: e.clientX,
    y: e.clientY,
  }
}

export const getKeyboardSelectionDelta = (e: KeyboardEvent | React.KeyboardEvent): { dx: number; dy: number } => {
  const step = e.shiftKey ? 10 : 1
  let dx = 0
  let dy = 0

  if (e.key === 'ArrowUp') dy = -step
  else if (e.key === 'ArrowDown') dy = step
  else if (e.key === 'ArrowLeft') dx = -step
  else if (e.key === 'ArrowRight') dx = step

  return { dx, dy }
}
