import { describe, it, expect, beforeEach } from 'vitest';
import { createStore } from 'jotai';
import {
	commandLineVisibleAtom,
	openCommandLineAtom,
	closeCommandLineAtom,
	commandLineStateAtom,
} from '../commands/store';

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

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

	it('commandLineVisible starts false', () => {
		expect(store.get(commandLineVisibleAtom)).toBe(false);
	});

	it('openCommandLine sets visible to true', () => {
		store.set(openCommandLineAtom);
		expect(store.get(commandLineVisibleAtom)).toBe(true);
	});

	it('closeCommandLine sets visible to false', () => {
		store.set(openCommandLineAtom);
		store.set(closeCommandLineAtom);
		expect(store.get(commandLineVisibleAtom)).toBe(false);
	});

	it('openCommandLine enters searching phase', () => {
		store.set(openCommandLineAtom);
		const state = store.get(commandLineStateAtom);
		expect(state.phase).toBe('searching');
	});

	it('closeCommandLine resets to idle phase', () => {
		store.set(openCommandLineAtom);
		store.set(closeCommandLineAtom);
		const state = store.get(commandLineStateAtom);
		expect(state.phase).toBe('idle');
	});
});
