// SelectList fuzzy filter regression tests

import assert from "node:assert/strict";
import { describe, it } from "vitest";
import { SelectList, type SelectListTheme } from "../select-list.js";

const noopTheme: SelectListTheme = {
	selectedPrefix: (t: string) => t,
	selectedText: (t: string) => t,
	description: (t: string) => t,
	scrollInfo: (t: string) => t,
	noMatch: (t: string) => t,
};

describe("SelectList setFilter", () => {
	it("empty_filter_shows_all_items", () => {
		const list = new SelectList(
			[
				{ value: "a", label: "Alpha" },
				{ value: "b", label: "Beta" },
			],
			5,
			noopTheme,
		);
		list.setFilter("   ");
		assert.equal(list.getSelectedItem()?.value, "a");
	});

	it("fuzzy_matches_non_prefix_subsequences_on_label_or_value", () => {
		const list = new SelectList(
			[
				{ value: "run-task", label: "Run task", description: "runner" },
				{ value: "other-cmd", label: "Other", description: "misc" },
			],
			5,
			noopTheme,
		);
		// "rs" hits r … s across "run-task" / label (not contiguous prefix-only)
		list.setFilter("rs");
		const selected = list.getSelectedItem();
		assert.ok(selected);
		assert.equal(selected!.value, "run-task");
	});
});
