import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]): string {
  return twMerge(clsx(inputs));
}

/**
 * A record's name with its demonstration marker taken off.
 *
 * Every seeded row is titled "DEMO — Halcyon Research" so that nobody mistakes
 * the sample book for a real one. That prefix is a label on the record, not
 * part of the name, and anything that reads the name positionally — initials,
 * a first name, a sort key — reads the label instead: seven Growth cards all
 * initialled "DE", and a landing page that greets the reader as "DEMO".
 */
export function withoutDemoPrefix(name: string): string {
  return name.replace(/^(DEMO|EXAMPLE)\s+—\s+/, '');
}

/** Up to two initials, for an avatar tile. Falls back rather than rendering empty. */
export function initials(name: string): string {
  return (
    withoutDemoPrefix(name)
      .split(/\s+/)
      .filter(Boolean)
      .slice(0, 2)
      .map((part) => part[0]?.toUpperCase() ?? '')
      .join('') || 'PIG'
  );
}
