// #region UtilsModule [C:1] [TYPE Module] [SEMANTICS utility, classnames, merge, helper]

// #region Utils:Module [TYPE Function]
/**
 * @PURPOSE: General utility functions (class merging)
 * @LAYER Infra
 * 
 * Merges Tailwind class names into a single string. Handles strings, falsy values,
 * numbers, arrays, and nested structures — compatible with clsx/classnames convention.
 */
type ClassValue = string | number | boolean | undefined | null | ClassValue[] | Record<string, boolean | undefined | null>;

function _flattenClassValue(input: ClassValue): string[] {
  if (typeof input === "string" && input.length > 0) return [input];
  if (typeof input === "number") return [String(input)];
  if (typeof input === "boolean") return [];
  if (input === null || input === undefined) return [];
  if (Array.isArray(input)) return input.flatMap(_flattenClassValue);
  if (typeof input === "object") {
    return Object.entries(input)
      .filter(([_, val]) => val)
      .map(([key]) => key);
  }
  return [];
}

export function cn(...inputs: ClassValue[]): string {
  return inputs.flatMap(_flattenClassValue).join(" ");
}
// #endregion Utils:Module

// #endregion UtilsModule
