import { describe, it, expect } from 'vitest';
import { renderHook } from '@testing-library/react';
import React from 'react';
import { Provider, createStore } from 'jotai';
import { useLayout, useGetGraphBounds, useFitToBounds } from '../hooks/useLayout';

function wrapper({ children }: { children: React.ReactNode }) {
	const store = createStore();
	return React.createElement(Provider, { store }, children);
}

describe('useLayout hooks', () => {
	describe('useGetGraphBounds', () => {
		it('returns bounds and nodes', () => {
			const { result } = renderHook(() => useGetGraphBounds(), { wrapper });
			expect(result.current.bounds).toBeDefined();
			expect(result.current.nodes).toBeDefined();
			expect(Array.isArray(result.current.nodes)).toBe(true);
		});
	});

	describe('useFitToBounds', () => {
		it('returns fitToBounds function', () => {
			const { result } = renderHook(() => useFitToBounds(), { wrapper });
			expect(typeof result.current.fitToBounds).toBe('function');
		});
	});

	describe('useLayout', () => {
		it('returns combined layout utilities', () => {
			const { result } = renderHook(() => useLayout(), { wrapper });
			expect(typeof result.current.fitToBounds).toBe('function');
			expect(result.current.graphBounds).toBeDefined();
			expect(result.current.graphNodes).toBeDefined();
			expect(result.current.selectionBounds).toBeDefined();
		});

		it('graphNodes is initially empty', () => {
			const { result } = renderHook(() => useLayout(), { wrapper });
			expect(result.current.graphNodes).toHaveLength(0);
		});
	});
});
