// #region UtilsTest [C:2] [TYPE Module] [SEMANTICS test, utils, classnames, cn]
// @BRIEF Unit tests for the cn() utility — class name merging with strings, objects,
//   arrays, falsy values, and edge cases.
// @LAYER Tests
// @RELATION BINDS_TO -> [UtilsModule]
// @TEST_CONTRACT: cn -> Merges strings with spaces
// @TEST_CONTRACT: cn -> Handles falsy values (null, undefined, false)
// @TEST_CONTRACT: cn -> Supports object syntax (truthy keys included)
// @TEST_CONTRACT: cn -> Supports nested arrays
// @TEST_CONTRACT: cn -> Handles numeric values

import { describe, it, expect } from 'vitest';

describe('cn — class name utility', () => {
	it('joins multiple class strings', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('foo', 'bar')).toBe('foo bar');
	});

	it('filters out null and undefined values', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('foo', null, 'bar', undefined)).toBe('foo bar');
	});

	it('filters out boolean false', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('foo', false, 'bar')).toBe('foo bar');
	});

	it('handles object syntax — includes truthy keys', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('base', { active: true, hidden: false })).toBe('base active');
	});

	it('handles nested arrays', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('foo', ['bar', ['baz']])).toBe('foo bar baz');
	});

	it('converts numbers to strings', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('p-', 4)).toBe('p- 4');
	});

	it('returns empty string for no arguments', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn()).toBe('');
	});

	it('returns "0" for number 0 since it is cast to string', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn(null, undefined, false, '')).toBe('');
		expect(cn(0)).toBe('0');
	});

	it('handles mixed nested arrays with objects', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('btn', ['btn-primary', { disabled: true }], { 'is-loading': false })).toBe(
			'btn btn-primary disabled',
		);
	});

	it('trims no extraneous whitespace', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn('   ')).toBe('   ');
	});

	it('handles deeply nested empty arrays', async () => {
		const { cn } = await import('$lib/utils.js');
		expect(cn([], [[], [[]]])).toBe('');
	});
});
// #endregion UtilsTest
