// Tiny classnames helper.
//
// We intentionally accept Preact Signals' "Signalish<string>" values (objects
// with a `.value`) because some projects pass signals directly as className.

type SignalLike<T> = { value: T };

export type ClassPart =
  | string
  | number
  | false
  | null
  | undefined
  | SignalLike<string | undefined | null>;

function unwrap(part: ClassPart): string | number | false | null | undefined {
  if (part && typeof part === 'object' && 'value' in part) return (part as any).value;
  return part as any;
}

export function cn(...parts: ClassPart[]): string {
  return parts
    .map(unwrap)
    .filter((p) => p !== false && p != null && p !== '')
    .map(String)
    .join(' ');
}
