/**
 * Gesture configuration for @use-gesture/react
 *
 * Input-source-aware configurations.
 * Components should select the appropriate config based on `primaryInputSourceAtom`.
 */

import type { InputSource } from '../core/input-classifier';

// =============================================================================
// Source-Specific Configs
// =============================================================================

/** Gesture config for finger input (larger thresholds for imprecise touch) */
const fingerGestureConfig = {
	eventOptions: { passive: false, capture: false },
	drag: {
		pointer: { touch: true, keys: false, capture: false, buttons: -1 },
		filterTaps: true,
		tapsThreshold: 10,  // Was 3 — too strict for fingers
		threshold: 10,       // Was 3 — needs larger dead zone
	},
} as const;

/** Gesture config for pencil/stylus input (precise, tight thresholds) */
const pencilGestureConfig = {
	eventOptions: { passive: false, capture: false },
	drag: {
		pointer: { touch: true, keys: false, capture: false, buttons: -1 },
		filterTaps: true,
		tapsThreshold: 3,
		threshold: 2,       // Very precise — small dead zone
	},
} as const;

/** Gesture config for mouse input */
const mouseGestureConfig = {
	eventOptions: { passive: false, capture: false },
	drag: {
		pointer: { touch: true, keys: false, capture: false, buttons: -1 },
		filterTaps: true,
		tapsThreshold: 5,   // Was 3
		threshold: 3,
	},
} as const;

// =============================================================================
// Config Selectors
// =============================================================================

/**
 * Get the appropriate node gesture config for the given input source.
 */
export function getNodeGestureConfig(source: InputSource) {
	switch (source) {
		case 'finger':
			return fingerGestureConfig;
		case 'pencil':
			return pencilGestureConfig;
		case 'mouse':
			return mouseGestureConfig;
	}
}

/**
 * Get the appropriate viewport gesture config for the given input source.
 */
export function getViewportGestureConfig(source: InputSource) {
	const base = getNodeGestureConfig(source);
	return {
		...base,
		eventOptions: { passive: false },
		pinch: {
			pointer: { touch: true },
		},
		wheel: {
			eventOptions: { passive: false },
		},
	} as const;
}

