import { cn } from '@/lib/cn';

type Props = {
    name: string;
    className?: string;
};

/**
 * Renders the configured site name with the accent gradient on the last
 * word — preserves the original "AppShot **Studio**" flourish for
 * multi-word names while still working for single-word brands. Used in
 * every surface that previously hardcoded "AppShot AI".
 */
export default function BrandedText({ name, className }: Props) {
    const trimmed = (name || '').trim();
    const lastSpace = trimmed.lastIndexOf(' ');
    const head = lastSpace === -1 ? '' : trimmed.slice(0, lastSpace + 1);
    const tail = lastSpace === -1 ? trimmed : trimmed.slice(lastSpace + 1);

    return (
        <span data-testid="branded-text" className={cn(className)}>
            {head}
            <span className="bg-gradient-to-r from-accent to-accent-secondary bg-clip-text text-transparent">
                {tail}
            </span>
        </span>
    );
}
