import { describe, it, expect, beforeEach } from 'vitest';
import { createStore } from 'jotai';
import {
	zoomAtom,
	panAtom,
	viewportRectAtom,
	zoomFocusNodeIdAtom,
	zoomTransitionProgressAtom,
	isZoomTransitioningAtom,
	ZOOM_TRANSITION_THRESHOLD,
	ZOOM_EXIT_THRESHOLD,
} from '../core/viewport-store';

describe('useCanvasViewport (atom-level)', () => {
	let store: ReturnType<typeof createStore>;

	beforeEach(() => {
		store = createStore();
	});

	it('zoom defaults to 1', () => {
		expect(store.get(zoomAtom)).toBe(1);
	});

	it('pan defaults to {x: 0, y: 0}', () => {
		const pan = store.get(panAtom);
		expect(pan.x).toBe(0);
		expect(pan.y).toBe(0);
	});

	it('viewportRect starts null', () => {
		expect(store.get(viewportRectAtom)).toBeNull();
	});

	it('zoom can be set', () => {
		store.set(zoomAtom, 2.5);
		expect(store.get(zoomAtom)).toBe(2.5);
	});

	it('pan can be set', () => {
		store.set(panAtom, { x: 100, y: -50 });
		expect(store.get(panAtom)).toEqual({ x: 100, y: -50 });
	});

	it('zoomFocusNodeId starts null', () => {
		expect(store.get(zoomFocusNodeIdAtom)).toBeNull();
	});

	it('zoom transition constants are defined', () => {
		expect(ZOOM_TRANSITION_THRESHOLD).toBeGreaterThan(0);
		expect(ZOOM_EXIT_THRESHOLD).toBeGreaterThan(0);
	});
});
