/* @vitest-environment node */

import { describe, it, expect } from "vitest";
import {
	normalizeNumericOptions,
	buildExplorerDropdownItems,
} from "./breadcrumbDropdowns";

describe("lib/frontend/explorer/breadcrumbDropdowns", () => {
	describe("normalizeNumericOptions", () => {
		it("returns null for non-arrays or empty arrays", () => {
			expect(normalizeNumericOptions(null)).toBe(null);
			expect(normalizeNumericOptions(undefined)).toBe(null);
			expect(normalizeNumericOptions([])).toBe(null);
		});

		it("deduplicates and sorts numeric strings descending", () => {
			expect(normalizeNumericOptions(["1", "10", "2", "2", ""])).toEqual([
				"10",
				"2",
				"1",
			]);
		});
	});

	describe("buildExplorerDropdownItems", () => {
		it("builds year items only when year is present", () => {
			const res = buildExplorerDropdownItems({
				branch: "NL01",
				year: "2024",
				yearOptions: ["2023", "2024", "2025"],
			});

			expect(res.yearItems?.[0]).toMatchObject({
				value: "2025",
				label: "2025",
				href: "/NL01/2025",
			});
		});

		it("builds month items with German labels", () => {
			const res = buildExplorerDropdownItems({
				branch: "NL01",
				year: "2024",
				month: "10",
				monthOptions: ["01", "10"],
			});

			// October must become "Oktober (10)" per formatter
			expect(res.monthItems?.find((x) => x.value === "10")?.label).toBe(
				"Oktober (10)"
			);
		});

		it("builds day items only when day is present", () => {
			const res = buildExplorerDropdownItems({
				branch: "NL01",
				year: "2024",
				month: "10",
				day: "23",
				dayOptions: ["01", "23"],
			});

			expect(res.dayItems?.find((x) => x.value === "23")?.href).toBe(
				"/NL01/2024/10/23"
			);
		});
	});
});
