import { describe, it, expect } from 'vitest';
import { BUILT_IN_PRESETS, getActionForEvent } from '../core/settings-presets';
import { CanvasEventType, BuiltInActionId, DEFAULT_MAPPINGS } from '../core/settings-types';

describe('settings-presets', () => {
	describe('BUILT_IN_PRESETS', () => {
		it('has 3 built-in presets', () => {
			expect(BUILT_IN_PRESETS.length).toBe(3);
		});

		it('all presets are marked isBuiltIn', () => {
			for (const preset of BUILT_IN_PRESETS) {
				expect(preset.isBuiltIn).toBe(true);
			}
		});

		it('all presets have unique IDs', () => {
			const ids = BUILT_IN_PRESETS.map((p) => p.id);
			expect(new Set(ids).size).toBe(ids.length);
		});

		it('default preset uses DEFAULT_MAPPINGS', () => {
			const defaultPreset = BUILT_IN_PRESETS.find((p) => p.id === 'default');
			expect(defaultPreset).toBeDefined();
			expect(defaultPreset!.mappings).toBe(DEFAULT_MAPPINGS);
		});

		it('minimal preset maps most actions to None', () => {
			const minimal = BUILT_IN_PRESETS.find((p) => p.id === 'minimal');
			expect(minimal).toBeDefined();
			expect(minimal!.mappings[CanvasEventType.NodeClick]).toBe(BuiltInActionId.None);
			expect(minimal!.mappings[CanvasEventType.NodeDoubleClick]).toBe(BuiltInActionId.None);
		});

		it('power-user preset enables advanced actions', () => {
			const power = BUILT_IN_PRESETS.find((p) => p.id === 'power-user');
			expect(power).toBeDefined();
			expect(power!.mappings[CanvasEventType.NodeDoubleClick]).toBe(BuiltInActionId.ToggleLock);
			expect(power!.mappings[CanvasEventType.BackgroundDoubleClick]).toBe(BuiltInActionId.CreateNode);
		});

		it('all presets cover all event types', () => {
			const eventTypes = Object.values(CanvasEventType);
			for (const preset of BUILT_IN_PRESETS) {
				for (const event of eventTypes) {
					expect(preset.mappings[event]).toBeDefined();
				}
			}
		});
	});

	describe('getActionForEvent', () => {
		it('returns mapped action', () => {
			const result = getActionForEvent(DEFAULT_MAPPINGS, CanvasEventType.BackgroundClick);
			expect(result).toBe(DEFAULT_MAPPINGS[CanvasEventType.BackgroundClick]);
		});

		it('returns None for unmapped event', () => {
			const emptyMappings = {} as any;
			const result = getActionForEvent(emptyMappings, CanvasEventType.NodeClick);
			expect(result).toBe(BuiltInActionId.None);
		});
	});
});
